Nested Recipe Inventory Manager
Reported by candidates from StackAdapt's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
StackAdapt's July 2026 OA has a problem that looks like a string-parsing chore and isn't. Nested Recipe Inventory Manager is a simulation over a DAG. Strip the cooking theme and it reduces to this: expand a recipe into raw totals, check them all against stock, and only then deduct. If you've got the OA in a day or two, this is the one to know cold. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic below is short enough to carry in your head.
The problem
Process operations on one recipe and raw-supply inventory manager. A recipe has a unique name, its own preparation time, and positive quantities of ingredients. An ingredient is either a previously added recipe or a raw ingredient. Operations ADD_RECIPE|name|time|ingredient:quantity,...: add a new recipe. Dependencies are listed before recipes that use them. Return OK. ADD_SUPPLY|ingredient|count: add count units to a raw ingredient's inventory. Return OK. PLACE_ORDER|dish: recursively expand the dish into total raw-ingredient requirements. If every requirement is available, deduct all of them and return true. Otherwise return false and leave every inventory count unchanged. LIST_OVER|minutes: return the lexicographically sorted names of recipes whose own preparation time is strictly greater than minutes, joined by commas. Return an empty string when none match. Return one result string for every operation, in input order. Function runRecipeManager(operations: String[]) → String[] Examples Example 1 operations = ["ADD_RECIPE|sauce|10|tomato:2","ADD_RECIPE|pasta|25|sauce:1,noodle:1","ADD_SUPPLY|tomato|4","ADD_SUPPLY|noodle|1","LIST_OVER|20","PLACE_ORDER|pasta","PLACE_ORDER|pasta","LIST_OVER|10"] return = ["OK","OK","OK","OK","pasta","true","false","pasta"] One pasta needs two tomatoes through sauce and one noodle. The first order succeeds and consumes that inventory. The second fails because no noodle remains, so it consumes nothing. Only pasta has an own preparation time strictly above either queried threshold. Example 2 operations = ["ADD_RECIPE|filling|30|bean:2,spice:1","ADD_RECIPE|wrap|15|filling:2,tortilla:1","ADD_SUPPLY|bean|4","ADD_SUPPLY|spice|2","ADD_SUPPLY|tortilla|1","PLACE_ORDER|wrap","LIST_OVER|15"] return = ["OK","OK","OK","OK","OK","true","filling"] Expanding two units of filling requires four beans and two spices, so the order exactly consumes all supplied raw ingredients. The strict time comparison includes filling but not the 15-minute wrap. Constraints 1 <= operations.length <= 500 Names contain only lowercase English letters, are non-empty, and have length at most 30. Recipe names are unique, dependencies form a directed acyclic graph, and every recipe dependency is added before the recipe that uses it. Every ingredient quantity, supply addition, and preparation time is a positive integer at most 10^9. Every expanded raw requirement and stored inventory total fits in a signed 64-bit integer. Every PLACE_ORDER names an added recipe, and every operation follows its documented format.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is separating check from commit. For PLACE_ORDER, expand the dish recursively into a map of raw ingredient to total quantity, multiplying by each quantity as you descend. Memoize the expansion per recipe, since recipes are immutable once added and dependencies always come first. Then loop over the map. If any raw total exceeds stock, return false and touch nothing. Otherwise deduct everything and return true. The pitfall is deducting while expanding, which corrupts inventory on a failed order. Another is overflow. The statement says totals fit in signed 64-bit, so use long. LIST_OVER is just a filter on each recipe's own time with a strict greater-than, then sort and join. Don't add up child times. If you freeze on the recursion live, StealthCoder can hand you the working structure, but the two-phase check is the whole problem.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Nested Recipe Inventory Manager cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass StackAdapt's OA.
StackAdapt reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Nested Recipe Inventory Manager FAQ
What's the real trick in the Nested Recipe Inventory Manager?+
Two phases. First expand the dish into total raw requirements without changing inventory. Then verify every requirement is covered. Only after that do you deduct. A failed order must leave all counts unchanged, so never mutate stock during expansion.
How hard is this OA question really?+
Medium at most. There's no fancy algorithm. The difficulty is careful state handling, multiplying quantities through nested levels, and using 64-bit integers. With only 500 operations, performance isn't a concern.
Do I need memoization for the recipe expansion?+
It's optional but cheap. Recipes never change once added, so you can cache each recipe's raw-ingredient map. Without it, plain recursion still works at 500 operations, but deep shared dependencies could multiply the work, so caching is safer.
How should LIST_OVER handle ties and empty results?+
Compare each recipe's own preparation time strictly greater than minutes. Equal times are excluded, as the wrap example shows. Sort the matching names lexicographically, join with commas, and return an empty string if nothing matches.
How do I prepare for this in 48 hours?+
Write the parser and a recursive expander once, using a hash map of recipes and a hash map of stock. Test both examples, especially the failed second order. Also test a case where a raw ingredient appears through two different sub-recipes, since totals must be merged.