In the Find All Possible Recipes from Given Supplies coding problem, you are a chef with a list of initial supplies. You want to make several recipes, but each recipe requires a specific set of ingredients. An ingredient can be either a basic supply or another recipe you've already made. You need to return a list of all recipes you can eventually complete.
Uber, Microsoft, and Google use this to test your understanding of dependency management. This is a classic "Dependency Graph" problem. It evaluations your proficiency with the Topological Sort interview pattern (Kahn's Algorithm). It tests whether you can represent recipes and ingredients as nodes and edges in a directed acyclic graph (DAG) and find an ordering that allows completion.
The problem is solved using Kahn's Algorithm (Topological Sort).
Supplies: ["yeast", "flour"].
Recipes: ["bread", "sandwich"].
Ingredients: bread: ["yeast", "flour"], sandwich: ["bread", "ham"].
bread needs 2 ingredients. Both are in supplies. In-degree becomes 0.sandwich needs 2 ingredients. bread is one, ham is the other.yeast, flour.yeast and flour bread's in-degree becomes 0. Add bread to queue.bread sandwich's in-degree becomes 1 (still needs ham).ham is not available. sandwich is never finished.
Result: ["bread"].Whenever you see "to do A, you must first do B," think Topological Sort. This pattern is applicable to everything from build systems (like Make or Gradle) to task scheduling and cooking recipes.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Apply Substitutions | Medium | Solve | |
| Design Excel Sum Formula | Hard | Solve | |
| Word Subsets | Medium | Solve | |
| Vowel Spellchecker | Medium | Solve | |
| Find Duplicate File in System | Medium | Solve |