Find All Possible Recipes from Given Supplies

Try to solve the Find All Possible Recipes from Given Supplies problem.

Statement

A list of recipes a chef can prepare from the supplied items is given. Ingredients required to prepare a recipe are mentioned in the ingredients list. The ithi_{th} recipe has the name recipesirecipes_{i}, and you can create it if you have all the needed ingredients from the ingredientsiingredients_{i} list. A recipe may be listed as an ingredient in a different recipe. For example, the input may specify that custard is an ingredient in a trifle recipe or that trifle is an ingredient in a custard recipe.

Identify which recipes a chef can prepare from the given ingredients from the supplies list.

Note: It is also considered valid input for two recipes to list each other in their ingredients. For example, the input may specify that custard is an ingredient in a trifle recipe and also that trifle is an ingredient in a custard recipe. Of course, if those are the only two recipes provided in the input, the expected output is an empty list.

Constraints:

  • n==n == recipes.length ==== ingredients.length
  • 1≤1 \leq n ≤100\leq 100
  • 1≤1 \leq ingredients[i].length, supplies.length ≤100\leq 100
  • 1≤1 \leq recipes[i].length, ingredients[i][j].length, supplies[k].length ≤10\leq 10
  • recipes[i], ingredients[i][j], and supplies[k] consist only of lowercase English letters.
  • All the combined values of recipes and supplies are unique.
  • Each ingredients[i] doesn’t contain any duplicate values.

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy