Streaming Ingredient Dishes
Reported by candidates from Harness's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Harness reportedly asked this one in July 2026, and it looks scarier than it is. A chef gets one ingredient a day, and you say yes or no on whether a dish can be cooked. Strip the story and it's a counting problem with a queue-order tiebreak. You track how many of each type are in stock, and you remember arrival order so the "oldest" rules work. If you've got an OA coming, this is simulation, not cleverness. StealthCoder sits invisible on your screen as a safety net if the tiebreak wording makes you blank mid-assessment.
The problem
A quick note: this problem is backed by a real Harness onsite interview report. The report directly gave the three ingredient types, streaming arrival model, dish rule, and chronological choice constraint, but it did not include an exact function interface, examples, or input limits. The core task match is about 90%. A chef receives one ingredient per day. Each ingredient is one of "fat", "fib", or "carb". After each day's ingredient arrives, decide whether the chef can cook one dish using currently stocked ingredients. A dish uses exactly three ingredients and is valid when at least two of the three chosen ingredients have the same type. When a dish can be cooked, consume one valid set immediately and output 1 for that day. Otherwise output 0. To respect the chronological rule from the interview report, choose the pair whose second ingredient arrived earliest; after removing that pair, use the oldest remaining ingredient as the third ingredient. Return the daily 0/1 results. Interview Follow-up At the start of the round, the interviewer said not to optimize yet and asked the candidate to focus on producing a working solution. Function canCookByDay(ingredients: String[]) → int[] Examples Example 1 ingredients = ["fat","fib","fat","carb","carb","fib"] return = [0,0,1,0,0,1] On day 3, the chef can use two fat ingredients and the oldest other ingredient. On day 6, the remaining stock has two carb ingredients and one fib. Example 2 ingredients = ["fat","fib","carb","fat"] return = [0,0,0,1] The first three ingredients are all different, so no dish is possible. After the second fat arrives, a dish can be cooked.
Reported by candidates. Source: FastPrep
Pattern and pitfall
What it really reduces to: keep a list of stocked ingredients in arrival order. After each arrival, check whether any type has count >= 2. If not, output 0. If yes, you must pick the pair whose second element arrived earliest. For each type with 2+ items, the second-oldest index is the pair's finish time. Take the type with the smallest one, remove those two items, then remove the oldest remaining item as the third. Output 1. Since a dish needs three ingredients, you also need at least three in stock. The common pitfall is removing the wrong third item, or forgetting that the third can be any type, even one matching the pair. The interviewer said not to optimize, so a simple list scan per day is fine. Run both examples by hand. StealthCoder is the hedge on the live OA if the selection rule trips you up under pressure.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Streaming Ingredient Dishes 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderYou've seen the question.
Make sure you actually pass Harness's OA.
Harness reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Streaming Ingredient Dishes FAQ
How hard is Streaming Ingredient Dishes really?+
Easy to medium. There's no fancy algorithm. The difficulty is reading the selection rule correctly and handling indices. Most failures come from picking the wrong pair or wrong third ingredient, not from complexity.
What's the trick?+
Keep ingredients in arrival order and compute, per type, the index of its second-oldest item. The type with the smallest such index gives the pair. Remove both, then remove the oldest leftover item as the third.
Do I need to optimize this?+
The report says the interviewer asked for a working solution first, not an optimized one. Scanning a list each day is acceptable. Only mention optimizations like per-type queues after you've got correct output on both examples.
What edge cases should I test?+
Fewer than three ingredients in stock, even with a matching pair, must output 0. Also test three of the same type, and cases where the oldest leftover shares the pair's type. Example 2 covers the all-different start.
How do I prepare in 48 hours?+
Practice simulation problems with ordered removal. Write a brute-force version, then trace both examples by hand. Focus on translating wordy rules into precise code, since that's where this question trips people up.