Emit an Out-of-Order Packet Stream in Order
Updated
Problem statement
Packets arrive one at a time. Two arrays of the same length, sequence and payloads, describe them in arrival order. Packet i has the sequence number sequence[i] and carries the payload payloads[i]. Sequence numbers are positive, and no two packets share one.
The receiver sends payloads out in sequence order. At the start it waits for sequence number 1. After each arrival, send out every payload that is now ready: the one it is waiting for, then the next number, and so on, until you reach a number that has not arrived yet. Hold any later packet until every packet before it has arrived.
Return one string array per arrival, listing the payloads that arrival lets you send, in order. If an arrival sends nothing, its array is empty.
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 arrive early, so they wait for packet 3. Its arrival sends payloads 3, 4, and 5 together: o, o, m. Packet 8 waits for 7. Its arrival sends packet 7's payload r, then packet 8's payload e. Every other arrival sends its own payload right away or nothing.
Example 2
sequence = [3,1,2]payloads = ["c","a","b"]return = [[],["a"],["b","c"]]Packet 3 arrives first and must wait, so the first array is empty. Packet 1 comes next and goes out alone as a. Then packet 2 arrives and sends both 2 and 3: b, then c.
Constraints
sequence.length == payloads.length.1 <= sequence.length <= 10^5.sequenceholds each number in1..nexactly once, wherenis the number of packets.- Payload strings are not empty.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)