Design an Ordered Stream
Updated
Problem statement
Given n, ids, and values, return the chunk of values an ordered stream outputs after each insert call.
The stream expects exactly n unique pairs, with IDs from 1 through n, and they can arrive in any order. Call i inserts (ids[i], values[i]), and the calls happen in that order.
After each insert, look at the smallest ID whose value has not been output yet. If that ID has arrived, output its value and the values of the IDs right after it, stopping at the first ID that has not arrived. Otherwise output an empty chunk.
Joined together, all chunks list every value in increasing ID order.
Function
orderedStreamChunks(n: int, ids: int[], values: String[]) → String[][]Examples
Example 1
n = 5ids = [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 outputs one value, inserting ID 2 outputs IDs 2 and 3, and the same happens later for IDs 4 and 5.
Example 2
n = 1ids = [1]values = ["only"]return = [["only"]]The only ID arrives in the first call, so that call outputs its value right away.
Example 3
n = 4ids = [2,4,1,3]values = ["b","d","a","c"]return = [[],[],["a","b"],["c","d"]]The stream waits for ID 1, then outputs IDs 1 and 2. The last call adds ID 3, which comes out with the waiting ID 4.
Constraints
1 <= n <= 1000.ids.length == values.length == n.idsis a permutation of the integers from1throughn.1 <= values[i].length <= 100.- Each value contains lowercase English letters.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
- Portfolio Tickers with Constant-Time Random PickCitadel · PHONE SCREENCitadel interview questions
- Randomized String MultisetLinkedIn · PHONE SCREENLinkedIn interview questions
- Build a Pivot Table with TotalsSigma Computing · PHONE SCREEN
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
- Process Banking OperationsVercel · OA
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions