Find All Recipes from Given Supplies

Given a list of recipes, their ingredient lists, and your initial supplies, return all recipes you can make. Pattern focus: Applications. This is a classic dependency-resolution problem solved with a topological queue.

Input Format

recipes = recipe names, ingredients = required ingredients per recipe, supplies = initial available items

Output Format

all recipes that can be made

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9

Examples

Example 1:

Input:

recipes = ["bread","sandwich"]
ingredients = [["yeast","flour"],["bread","meat"]]
supplies = ["yeast","flour","meat"]

Output:

["bread","sandwich"]

Explanation:

Bread can be made first, which unlocks sandwich.

Example 2:

Input:

recipes = ["burger","fries"]
ingredients = [["bread","meat"],["potato"]]
supplies = ["meat","potato"]

Output:

["fries"]

Explanation:

Only fries can be prepared from the available supplies.

Example 3:

Input:

recipes = ["cake"]
ingredients = [["flour","egg"]]
supplies = ["flour","egg"]

Output:

["cake"]

Explanation:

All ingredients are available, so the recipe can be prepared.

Loading...
Find All Recipes from Given Supplies