Determine which recipes can be prepared from an initial set of supplies and other recipes that become available later.
You are given a list of recipe names, a list of ingredient lists, and a list of starting supplies.
A recipe can be prepared if every ingredient in its list is already available. An ingredient is available if it is either one of the initial supplies or a recipe that has already been prepared.
Return all recipes that can eventually be made. You may use the prepared recipes as ingredients for other recipes, and recipes can depend on one another. If a dependency cycle prevents a recipe from ever being made, it should not appear in the answer.
The order of the returned recipes does not matter, as long as every makeable recipe is included exactly once.
Input Format
recipes: list of recipe namesingredients:ingredients[i]lists the ingredients needed forrecipes[i]supplies: list of initially available items
Each recipe name is unique.
Output Format
Return a list of all recipes that can be prepared using the initial supplies and any recipes that become available later.
Constraints
1 <= recipes.length == ingredients.length <= 100- Recipe names and ingredient names are non-empty strings
- Ingredient names may refer to either supplies or other recipes
- Answer order does not matter
Example 1
Input
recipes = ["bread","sandwich","burger"], ingredients = [["yeast","flour"],["bread","meat"],["sandwich","bread"]], supplies = ["yeast","flour","meat"]
Output
["bread","sandwich","burger"]
Explanation
Bread can be made first from the supplies. Then sandwich can be made using bread and meat. Finally burger can be made using sandwich and bread.
Example 2
Input
recipes = ["cake","icing"], ingredients = [["flour","sugar"],["cake","sugar"]], supplies = ["flour","sugar"]
Output
["cake","icing"]
Explanation
Cake is makeable from the supplies. Once cake is available, icing becomes makeable as well.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.