Find All Possible Recipes from Given Supplies

You have n recipes. recipes[i] can be made once you have every item in ingredients[i], and an ingredient may itself be another recipe. supplies lists the items you start with in unlimited quantity. Return every recipe you can make, in any order.

30:00

Find All Possible Recipes from Given Supplies
medium
Free written solution
Topics
Companies

You have n recipes. recipes[i] can be made once you have every item in ingredients[i], and an ingredient may itself be another recipe. supplies lists the items you start with in unlimited quantity. Return every recipe you can make, in any order.

Example 1:
Input: {"recipes":["bread"],"ingredients":[["yeast","flour"]],"supplies":["yeast","flour","corn"]}
Output: ["bread"]
Constraints:
  • n=recipes.length=ingredients.lengthn = \text{recipes.length} = \text{ingredients.length}

  • 1≤n≤1001 \leq n \leq 100

  • 1≤ingredients[i].length,supplies.length≤1001 \leq \text{ingredients}[i].\text{length}, \text{supplies.length} \leq 100

  • 1≤recipes[i].length,ingredients[i][j].length,supplies[k].length≤101 \leq \text{recipes}[i].\text{length}, \text{ingredients}[i][j].\text{length}, \text{supplies}[k].\text{length} \leq 10

  • All values are lowercase English letters; recipes and supplies combined are unique; each ingredients[i] has no duplicates.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"recipes":["bread"],"ingredients":[["yeast","flour"]],"supplies":["yeast","flour","corn"]}

1 recipe and 3 starting supplies. A recipe is ready once every one of its ingredients is in hand.

pantry

grey = supply, green = made, dim = already used

yeast

flour

corn

queue

not filled yet

recipes

bread

?

yeast

flour

made so far

[]

Variables
VariableValue
itemnull
queue0
made0
DepthFunction Call
Stack empty
0/9