Reported November 2022
Bloomberghash table

Emit an Out-of-Order Packet Stream in Order

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The edge case that breaks a naive solution here is the buffered packet that sits quietly until its predecessor finally shows up. This Bloomberg OA, reported in November 2022, gives you parallel arrays of sequence numbers and payloads and asks you to emit contiguous runs as packets arrive out of order. One output array per arrival, empty when nothing releases. It's a buffering problem wearing a sorting hint. If you blank on the flush logic mid-assessment, StealthCoder runs invisibly on screen and gives you a working solution as a hedge. Better to know the trick before you open the timer.

The problem

Packets arrive in the order described by parallel arrays sequence and payloads. Packet i has the unique positive sequence number sequence[i] and payload payloads[i].
The receiver initially expects sequence number 1. After each arrival, emit the longest newly available contiguous run beginning at the expected number. Buffer later packets until every predecessor has arrived.
Return one string array per arrival; use an empty array when that arrival releases nothing.

Function
emitPackets(sequence: int[], payloads: String[]) → String[][]

Examples
Example 1
sequence = [1,2,4,5,3,6,8,7,9]
payloads = ["b","l","o","m","o","b","e","r","g"]
return = [["b"],["l"],[],[],["o","o","m"],["b"],[],["r","e"],["g"]]
Packets 4 and 5 wait for packet 3; its arrival releases payloads 3, 4, and 5 together. Packet 8 waits for 7, whose arrival releases packet 7's payload r before packet 8's payload e.
Example 2
sequence = [3,1,2]
payloads = ["c","a","b"]
return = [[],["a"],["b","c"]]
Packet 3 is buffered; packet 1 emits alone, then packet 2 releases both 2 and 3.

Constraints
sequence.length == payloads.length.
1 <= sequence.length <= 10^5.
sequence is a permutation of 1..n.
Payload strings are nonempty.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Don't sort the whole input. You need output after every arrival, so sorting up front loses the order. Use a hash map (or an array of size n+1, since sequence is a permutation of 1..n) to buffer payloads by sequence number, and keep one pointer called next, starting at 1. On each arrival, store the payload, then loop: while next is in the buffer, append it to this arrival's result and increment next. If the loop never runs, append an empty array. Each packet is emitted exactly once, so the total is O(n), which matters at 10^5. The common pitfall is emitting the arriving packet by itself when it doesn't match next, or returning only the first release instead of the full run. Check Example 2: packet 3 buffers, 1 emits alone, 2 releases both 2 and 3 in order.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Emit an Out-of-Order Packet Stream in Order 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Emit an Out-of-Order Packet Stream in Order FAQ

What's the trick in the Bloomberg out-of-order packet problem?+

Keep a buffer keyed by sequence number and a pointer to the next expected number. After each arrival, store the payload, then keep emitting while the pointer exists in the buffer. Each packet is emitted once, so it runs in linear time.

Do I need to sort the sequence array?+

No. Sorting destroys the arrival order, and you must output a result per arrival. Since sequence is a permutation of 1..n, a plain array indexed by sequence number works as the buffer. No sort and no heap needed.

How hard is this one really?+

Easy to medium. The idea is simple once you see it, but the output format trips people up. You need one inner array per arrival, including empty ones, and releases must come out in ascending sequence order.

What edge cases should I test?+

Test fully reversed input like [3,2,1], where nothing emits until the last arrival. Test already sorted input, where every arrival emits one payload. Also test a single packet. Verify empty arrays appear for buffered arrivals and that one arrival can release a long run.

How do I prepare for this in 48 hours?+

Write this solution from scratch twice using a pointer plus buffer. Then do a couple of similar stream or ordering problems with maps. Focus on the while-loop flush and per-arrival output structure. Skip heavy theory, since the pattern is narrow and the code is short.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it