Merge Multiple Sorted Streams
Updated
Problem statement
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 <= 1000 <= 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.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Select the Top User MatchesDuolingo · PHONE SCREENDuolingo interview questions
- Meeting Rooms IIQuince · PHONE SCREENQuince interview questions
- Kth Largest Element in an ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Meeting Rooms IISecuronix · PHONE SCREEN
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions