Streaming Ingredient Dishes
Learn this problemProblem statement
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.