Reported October 2019
Bloomberghash table

Ordered Acknowledgement API

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 kills the naive answer here is the duplicate ack and the huge ID. Bloomberg reported this Ordered Acknowledgement API question in October 2019, and it looks like a simple tracking problem until you try to size an array for IDs up to 2^31-1. You need the largest x where 1 through x have all arrived, after every single message. It's a contiguous-prefix problem dressed up as an API. If your mind goes blank mid-assessment, StealthCoder runs invisibly on screen as a safety net, but the idea is short enough to hold in your head.

The problem

Positive message IDs arrive out of order in acknowledgements. After each arrival, return the largest ID x such that every ID from 1 through x has arrived. Return -1 while ID 1 is still missing.
Duplicate acknowledgements do not change state.

Function
latestAfterAcknowledgements(acknowledgements: int[]) → int[]

Examples
Example 1
acknowledgements = [2,1,5,4,3]
return = [-1,2,2,2,5]
The contiguous prefix advances only when every gap is filled.

Constraints
At most 2 * 10^5 acknowledgements.
IDs are positive signed 32-bit integers.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a hash set plus a single pointer that only moves forward. Keep a set of seen IDs and a variable next, starting at 1 and meaning the smallest ID still missing. On each ack, add the ID to the set. Then while next is in the set, increment next. The answer for that step is next - 1, or -1 when next is still 1. Since next never moves backward, total work is O(n) amortized across all 2 * 10^5 acks. The pitfall is allocating a boolean array indexed by ID. IDs go up to a signed 32-bit max, so that blows memory. Use a set. Duplicates need no special code, since adding an existing ID changes nothing. Another slip is recomputing the prefix from 1 each time, which goes quadratic. StealthCoder is your hedge in the live OA if the pointer loop slips your mind, but the pattern is small.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Ordered Acknowledgement API 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Ordered Acknowledgement API FAQ

What's the trick in the Bloomberg Ordered Acknowledgement API problem?+

Track a set of arrived IDs and a pointer for the smallest missing ID. After each ack, advance the pointer while it's in the set. The answer is pointer - 1, or -1 if the pointer is still 1. The pointer only moves forward, so it's linear overall.

Why can't I just use a boolean array?+

IDs are positive signed 32-bit integers, so they can reach about 2.1 billion. An array indexed by ID won't fit in memory. A hash set stores only the IDs that actually arrived, at most 2 * 10^5 of them.

How do duplicate acknowledgements affect the answer?+

They don't. Adding an ID that's already in the set is a no-op, and the pointer won't move unless a new gap gets filled. The output for that step just repeats the previous value, which is what the problem wants.

What's the time complexity I should aim for?+

O(n) amortized. Each ID is inserted once and the pointer advances at most once per distinct ID. Restarting the prefix scan from 1 after every ack is O(n^2) and will time out on 2 * 10^5 inputs.

How do I prep for this in 48 hours?+

Write it from scratch twice with a set and a pointer. Test [2,1,5,4,3], a repeated ID, an input starting with a large ID, and an input where 1 arrives last. Those four cases cover the traps. Bloomberg reported it in October 2019, so expect variants.

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