Find All Possible Recipes from Given Supplies
Problem statement
You are given recipe names, the ingredients required by each recipe, and initially available supplies. A completed recipe becomes an available supply and may unlock other recipes.
Return every recipe that can eventually be produced, in the same order that recipes appear in the input.
Function
findAllRecipes(recipes: String[], ingredients: String[][], supplies: String[]) → String[]Examples
Example 1
recipes = ["bread"]ingredients = [["yeast","flour"]]supplies = ["yeast","flour","corn"]return = ["bread"]Both ingredients are initially available.
Example 2
recipes = ["bread","sandwich"]ingredients = [["yeast","flour"],["bread","meat"]]supplies = ["yeast","flour","meat"]return = ["bread","sandwich"]Bread is produced first and then serves as an ingredient for sandwich.
Constraints
1 <= recipes.length == ingredients.length <= 10^5.- Each recipe has at least one distinct ingredient.
- Recipe names are unique, supply names are unique, and total ingredient entries are at most
2 * 10^5.