Find All Possible Recipes from Given Supplies

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

Statement

You are given information about n different recipes. Each recipe is listed in the array recipes, and its corresponding ingredients are provided in the 2D2D array ingredients. The ithi^{th} recipe, recipes[i], can be prepared if all the necessary ingredients listed in ingredients[i] are available. Some ingredients might need to be created from other recipes, meaning ingredients[i] may contain strings that are also in recipes.

Additionally, you have a string array supplies that contains all the ingredients you initially have, and you have an infinite supply of each.

Return a list of all the recipes you can create. The answer can be returned in any order.

Note: It is possible for two recipes to list each other as ingredients. However, if these are the only two recipes provided, the expected output is an empty list.

Constraints:

  • 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.

Continue your learning journey with a 14-day free trial.

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