As reported: Indeed SDE 2 (Data Engineering) loop (2025), Karat phone screen 1: given recipes and raw materials, find the dishes that can be prepared — a hash map and strings problem of LeetCode-medium difficulty.
This is LeetCode 2115 — Find All Possible Recipes from Given Supplies.
You have n recipes: recipes[i] is a dish name and ingredients[i] lists what it needs. An ingredient is either a raw supply or another recipe. supplies lists the raw materials you have in unlimited quantity.
A recipe can be made when every one of its ingredients is available — a supply, or a recipe that can itself be made. Return all recipes you can make, in any order.
Example 1
recipes = ["bread"], ingredients = [["yeast","flour"]], supplies = ["yeast","flour","corn"]
-> ["bread"]
Example 2
recipes = ["bread","sandwich"], ingredients = [["yeast","flour"],["bread","meat"]],
supplies = ["yeast","flour","meat"]
-> ["bread","sandwich"]
sandwich needs bread, which can be made.
Example 3
recipes = ["a","b"], ingredients = [["b"],["a"]], supplies = []
-> []
Each needs the other: neither can be made.
Constraints: 1 ≤ n ≤ 100; 1 ≤ ingredients[i].length, supplies.length ≤ 100; names are 1–10 lowercase letters; recipe names are distinct, all distinct from supplies; an ingredient list has no duplicates.
Code runner format: three lines — recipes, ingredients, supplies (LeetCode's test-case format). Implement findAllRecipes(recipes, ingredients, supplies); the harness sorts and prints the result.