Reported September 2022
Bloombergheap priority queue

Merge Multiple Sorted Streams

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

Bloomberg reportedly sent this one in September 2022, and the detail that matters is the line telling you not to concatenate and re-sort. The task is to merge up to 100 sorted streams, with duplicates kept and empty streams allowed. It looks like a warmup, but the statement is steering you toward a min-heap of stream heads. If you've got an OA invite, expect the same shape with different wrapping. StealthCoder is a safety net here if you blank on the heap mechanics mid-assessment, since it sits invisibly and reads the problem for you.

The problem

You are given streams, where each inner array is an independently sorted stream of integers in nondecreasing order. Merge every value from every stream into one nondecreasing array.
Preserve every occurrence, including duplicates. Empty streams are valid. Process the inputs as independent ordered streams rather than concatenating and sorting all values again.

Function
mergeSortedStreams(streams: int[][]) → int[]

Examples
Example 1
streams = [[1,4,7],[2,2,9],[3,8]]
return = [1,2,2,3,4,7,8,9]
The next smallest available head is selected until every stream is exhausted. Both copies of 2 remain in the result.
Example 2
streams = [[],[-5,0,6],[1],[1,10]]
return = [-5,0,1,1,6,10]
Empty streams contribute nothing, and equal values from different streams are both preserved.
Example 3
streams = []
return = []
With no streams, the merged result is empty.

Constraints
0 <= streams.length <= 100
0 <= streams[i].length
The total number of values across all streams is at most 100000.
-1000000000 <= streams[i][j] <= 1000000000
Every inner array is sorted in nondecreasing order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a min-heap holding one entry per stream: (value, stream index, position). Pop the smallest, append it to the result, then push the next element from that same stream if one exists. Skip empty streams when seeding the heap. That gives O(N log k) where N is total values (up to 100000) and k is the number of streams (up to 100). The common pitfall is concatenating and sorting. It passes the examples but ignores the stated requirement, and it can cost you on review. Another pitfall is heap tie-breaking: if two values are equal and your tuple compares something unorderable, some languages crash, so include the stream index. Also handle streams = [] and all-empty input. If you freeze on heap syntax live, StealthCoder can give you a working version as a hedge.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Merge Multiple Sorted Streams 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as merge k sorted lists. If you have time before the OA, drill that.

⏵ The honest play

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

Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Multiple Sorted Streams FAQ

What's the trick in Merge Multiple Sorted Streams?+

Use a min-heap seeded with the first element of each non-empty stream. Pop the smallest, append it to the output, and push the next element from the same stream. Repeat until the heap is empty. Duplicates are preserved naturally because every popped value gets appended.

Can I just concatenate everything and sort?+

It produces the right output, but the statement explicitly says to process inputs as independent ordered streams rather than re-sorting everything. Concatenate-and-sort is O(N log N) and ignores the sorted structure. Use the heap approach, which is O(N log k) with k at most 100.

How hard is this really?+

Easy to medium. It's the classic k-way merge. If you've written a heap with tuples before, it's about ten lines. The difficulty is edge cases: empty streams, an empty outer array, duplicates across streams, and negative values up to a billion in magnitude.

Is the k-way merge pattern still asked?+

Yes. Bloomberg reportedly used this variant in September 2022, and k-way merge shows up often because it tests heaps and index tracking together. Expect variants like merging linked lists, finding the kth smallest across lists, or merging with a custom comparator.

How do I prepare in 48 hours?+

Write the heap-based merge from scratch twice in your OA language. Know its priority queue API cold, including how tuples compare. Then test empty outer input, all-empty streams, duplicates across streams, and a single stream. That covers nearly every failure mode for this problem.

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