FastPrepAvailable Recipes from Initial Supplies

Available Recipes from Initial Supplies

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

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.

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Amazon hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week