Design an Ordered Stream
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Bloomberg OA, reported in February 2026, is rescanning the whole array after every insert. Ordered Stream looks like a toy, but the grader checks every chunk, so a sloppy pointer gives you wrong output on the very first out-of-order case. The pattern is design: a small stateful object with a buffer and a pointer. If you blank under the timer, StealthCoder is the invisible safety net that reads the problem and hands you a working solution. Know the trick first, though, and you won't need it.
The problem
An ordered stream expects exactly n unique pairs whose IDs are the integers from 1 through n. The pairs arrive in arbitrary order. The arrays ids and values describe the insert calls in time order: call i inserts (ids[i], values[i]). After each insertion, return the largest contiguous chunk of values beginning at the smallest ID that has not been returned yet. Return an empty chunk when that next ID is still missing. Return one chunk for every insertion. Concatenating all returned chunks must produce the values in increasing ID order. Function orderedStreamChunks(n: int, ids: int[], values: String[]) → String[][] Examples Example 1 n = 5 ids = [3,1,2,5,4] values = ["ccccc","aaaaa","bbbbb","eeeee","ddddd"] return = [[],["aaaaa"],["bbbbb","ccccc"],[],["ddddd","eeeee"]] ID 3 arrives before IDs 1 and 2, so it waits. Inserting ID 1 emits one value; inserting ID 2 then emits both IDs 2 and 3. The same behavior later joins IDs 4 and 5. Example 2 n = 1 ids = [1] values = ["only"] return = [["only"]] The first and only expected ID arrives immediately. Example 3 n = 4 ids = [2,4,1,3] values = ["b","d","a","c"] return = [[],[],["a","b"],["c","d"]] The stream waits for ID 1, then emits IDs 1 and 2. The final insert fills ID 3 and releases the already stored ID 4. Constraints 1 <= n <= 1000. ids.length == values.length == n. ids is a permutation of the integers from 1 through n. 1 <= values[i].length <= 100. Each value contains lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep an array of size n+1 and a pointer ptr starting at 1. On each insert, store values[i] at slot ids[i]. Then, if slot ptr is filled, walk forward while slots are filled, collect them into a chunk, and advance ptr. If slot ptr is empty, return an empty list. The pitfall is resetting the scan to index 1 each time, or forgetting to advance ptr permanently, which duplicates values across chunks. Another trap is returning null instead of an empty list. Since ptr only moves forward, total work is O(n) across all calls, not O(n^2). Walk Example 3 by hand: [2,4,1,3] gives [], [], [a,b], [c,d]. If the live OA rattles you and the pointer logic slips, StealthCoder runs invisibly on screen as a hedge, but this one is simple enough to write cold.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Design an Ordered Stream 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Design an Ordered Stream FAQ
How hard is the Bloomberg Ordered Stream question really?+
Easy. It's a design problem with one array and one pointer. The difficulty is in the details: emitting the right chunk after each insert and returning empty lists when the next ID is missing. n is at most 1000, so performance isn't a concern.
What's the trick to Design an Ordered Stream?+
Store each value at its ID index and keep a persistent pointer to the next ID not yet returned. After each insert, advance the pointer while slots are filled and collect those values. The pointer never moves backward, so you never rescan old data.
What's the most common bug on this problem?+
Restarting the scan from ID 1 on every insert, which repeats already-returned values in later chunks. The second most common is returning null instead of an empty list when the pointer's slot is still empty. Test with ids [3,1,2,5,4] to catch both.
Is the design pattern still asked in OAs like Bloomberg's?+
Yes. Small stateful classes and simulation-style tasks keep showing up because they test clean state handling more than clever algorithms. This one was reported in February 2026. Expect similar buffer-plus-pointer problems, so practice tracking state across calls.
How do I prepare for this in 48 hours?+
Write this solution from memory twice, then trace Example 1 and Example 3 by hand. Focus on the pointer advancing and the empty-chunk case. Then do a couple of other small design problems that keep state between calls. That's enough for this level of difficulty.