Imagine you're a master chef with a cookbook of recipes and a pantry full of supplies. Your challenge is to determine which recipes you can actually cook!
You have n different recipes, where each recipe has a name and requires specific ingredients. Here's the twist: some recipes can serve as ingredients for other recipes. For example, you might need "dough" to make "pizza", but "dough" itself is another recipe in your cookbook.
Given:
- recipes[] - Array of recipe names
- ingredients[][] - 2D array where ingredients[i] contains all ingredients needed for recipes[i]
- supplies[] - Array of ingredients you initially have (infinite supply)
Goal: Return a list of all recipes you can make, considering that recipes can depend on other recipes. The order doesn't matter.
Note: Two recipes may contain each other in their ingredients (circular dependencies), but you should only return recipes that can actually be completed.
Input & Output
Constraints
- n == recipes.length == ingredients.length
- 1 β€ n β€ 100
- 1 β€ ingredients[i].length β€ 100
- 1 β€ supplies.length β€ 100
- 1 β€ recipes[i].length, ingredients[i][j].length, supplies[k].length β€ 10
- All strings consist of only lowercase English letters
- Each ingredients[i] does not contain duplicates