Available Recipes from Initial Supplies
Problem statement
You are given distinct recipe names in recipes. Row ingredients[i] lists everything needed to make recipes[i]. An ingredient can be an initial supply, another recipe, or a name that is unavailable.
Every initial supplies item is available in unlimited quantity. Whenever every ingredient of a recipe is available, that recipe also becomes available in unlimited quantity and can be used by other recipes. A recipe with no ingredients is available immediately. Recipe-to-recipe dependencies form a directed acyclic graph.
Examples
Example 1
recipes = ["bread","sandwich"]ingredients = [["flour","water"],["bread","ham"]]supplies = ["flour","water","ham"]return = ["bread","sandwich"]Bread becomes available first, so it can then enable sandwich.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.