Reported September 2023
Optiverhash table

Numbers Station Message Decoder

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

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

The Optiver OA reported in September 2023 hides its difficulty in one place: samples arrive out of order, and a naive rescan after every insert will die on 5 * 10^5 inputs. The Numbers Station Message Decoder asks you to stream characters keyed by sequence ID, detect hyphen-wrapped runs of two or more letters, and emit only the best completed message per insert. If you're staring at the invite and the edge cases feel slippery, that's the point. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment.

The problem

A radio broadcast arrives as samples of the form sequence character. Samples may arrive out of sequence order. A complete message consists of at least two lowercase letters at consecutive sequence IDs, immediately surrounded by hyphens at the preceding and following IDs.
When inserting one sample completes several messages at once, output only the completed message with the greatest ending sequence ID.
After outputting a message, never output a message whose ending sequence ID is lower than or equal to the last output message's ending sequence ID.
A one-letter fragment between two hyphens is ignored.
Sequence IDs are unique in the input stream.
Process every sample and return completed messages in callback order.

Function
decodeNumberStationMessages(samples: String[]) → String[]

Examples
Example 1
samples = ["1 -","2 h","3 e","4 y","5 -","6 b","7 -"]
return = ["hey"]
The range from 1 through 5 completes hey. The later one-letter fragment b is ignored.
Example 2
samples = ["1 -","2 h","3 e","5 -","6 b","7 y","8 e","9 -","4 y"]
return = ["bye"]
bye completes first with ending ID 9. When sample 4 y later completes hey, its ending ID 5 is obsolete.

Constraints
1 <= samples.length <= 5 * 10^5
0 < sequenceId <= 2^64 - 1
Every character is a lowercase English letter or -.
Every sequence ID appears at most once.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is local updates. Store samples in a hash map by ID, and when one lands, only look at the run of consecutive IDs around it. Think of maximal segments: a hyphen, letters, a hyphen. Inserting an ID can merge neighbors, so track left and right extents with union-find or a map of segment boundaries. After each insert, check which completed messages touch the new ID, then pick the one with the greatest ending ID. Compare it to the last output ending ID and skip it if it's lower or equal. Example 2 is the pitfall: hey completes late, but its end ID 5 is below 9, so it's dropped. Also watch IDs up to 2^64 - 1, which overflow signed 64-bit ints, and the one-letter fragments that must be ignored. If the merge logic tangles during the live OA, StealthCoder is the hedge that gives you a clean structure fast.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Numbers Station Message Decoder 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 StealthCoder

Related leaked OAs

⏵ The honest play

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

Optiver 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.

Numbers Station Message Decoder FAQ

What's the core trick in Numbers Station Message Decoder?+

Don't rescan the stream. Keep a map from sequence ID to character and only inspect the consecutive run around each newly inserted ID. A message is hyphen, two or more letters, hyphen, so you check boundaries locally and merge segments as gaps fill in.

How do I handle out-of-order samples?+

Store every sample by ID and treat each insert as a possible gap-filler. Look left and right for adjacent IDs, join them into a segment, and re-evaluate only that segment. Late arrivals like sample 4 in Example 2 can complete a message that is already obsolete.

Why is hey dropped in Example 2?+

bye completed first with ending ID 9. When sample 4 later completes hey, its ending ID is 5, which is not greater than 9. The rule says never output a message ending at or below the last output ending ID, so hey is skipped.

What edge cases break a naive solution?+

Several messages completing from one insert, where you must output only the highest ending ID. One-letter fragments between hyphens that must be ignored. Sequence IDs up to 2^64 - 1 that overflow signed 64-bit types. And repeated hyphens that start new boundaries.

How do I prepare for this in 48 hours?+

Practice streaming problems with out-of-order inserts, like merging intervals or consecutive-segment tracking with hash maps or union-find. Write the boundary-merge logic by hand once, then test it on both examples plus a case where one insert completes two messages.

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

OA at Optiver?
Invisible during screen share
Get it