...

/

Solution: Find All Possible Recipes from Given Supplies

Solution: Find All Possible Recipes from Given Supplies

Let’s solve the Find All Possible Recipes from Given Supplies problem using the Topological Sort pattern.

Statement

You are given information about nn different recipes. Each recipe is listed in the array recipes, and its corresponding ingredients are provided in the 2D array ingredients. The ithi^{th} recipe, recipes[i], can be prepared if all the necessary ingredients listed in ingredients[i] are available. Some ingredients might need to be created from other recipes, meaning ingredients[i] may contain strings that are also in recipes.

Additionally, you have a string array supplies that contains all the ingredients you initially have, and you have an infinite supply of each.

Return a list of all the recipes you can create. The answer can be returned in any order.

Note: It is possible for two recipes to list each other as ingredients. However, if these are the only two recipes provided, the expected output is an empty list.

Constraints:

  • n ==== ...