Merge Multiple Sorted Lists
Updated
Problem statement
You are given lists, an array of sorted integer lists. Each inner list is in nondecreasing order. Merge all of their values into one new list in nondecreasing order.
Every occurrence from every input list must appear exactly once in the result. Keep duplicates, including equal values within one list, across different lists, and in identical input lists. The outer lists may appear in any order.
Some inner lists may be empty. If the outer array is empty, or every inner list is empty, return an empty array.
Do not change the outer input or any inner list. Return a new array that is independent of all input lists and results from earlier calls. Each call works only with its own input.
Function
mergeSortedLists(lists: int[][]) → int[]Examples
Example 1
lists = [[1,4,7],[2,3,8],[0,5,6]]return = [0,1,2,3,4,5,6,7,8]The three lists contain each integer from 0 through 8 exactly once. Merging them in ascending order gives [0,1,2,3,4,5,6,7,8].
Example 2
lists = [[],[-3,-1,-1],[0,0,2],[]]return = [-3,-1,-1,0,0,2]The empty lists add no values. The other lists contain -3, two copies of -1, two copies of 0, and 2. Keep every copy and return [-3,-1,-1,0,0,2].
Example 3
lists = []return = []There are no input lists and no values to merge. Return an empty array.
Constraints
0 <= lists.length <= 60.- Each inner list contains between 0 and 60 integers, inclusive.
- Every integer in
listsis between-10^6and10^6, inclusive. - Each inner list is in nondecreasing order.
- The total number of integers across all lists is at most 60.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- 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
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- 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
- Merge Multiple Sorted StreamsNVIDIA · PHONE SCREENNVIDIA interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
Interview reports that mention this question
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)