Merge k Sorted Lists
Updated
Problem statement
You are given an array lists containing k linked-list heads. Every linked list is sorted in ascending order.
Merge all of the linked lists into one ascending linked list and return its head.
Function
mergeKLists(lists: ListNode[]) → ListNodeExamples
Example 1
lists = [[1,4,5],[1,3,4],[2,6]]return = [1,1,2,3,4,4,5,6]The linked lists are:
1 -> 4 -> 5
1 -> 3 -> 4
2 -> 6Merging them produces the sorted linked list 1 -> 1 -> 2 -> 3 -> 4 -> 4 -> 5 -> 6.
Example 2
lists = []return = []Example 3
lists = [[]]return = []Constraints
k == lists.length0 <= k <= 10^40 <= lists[i].length <= 500-10^4 <= lists[i][j] <= 10^4- Each
lists[i]is sorted in ascending order. - The sum of all
lists[i].lengthvalues does not exceed10^4.
More Oracle Phone Screen questions
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
- Shortest Window by Distinct-Value SumPHONE SCREEN · Seen Oct 2026
- Detect a Cycle in a Directed GraphPHONE SCREEN · Seen Oct 2026
- Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Remove Adjacent Duplicates in String IIPHONE SCREEN · Seen Oct 2026
- Sum Root-to-Leaf Binary NumbersPHONE SCREEN · Seen Oct 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Oct 2026
- Next PermutationPHONE SCREEN · Seen Sep 2026
- Valid ParenthesesPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Merge k Sorted ListsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Greedy Person-Cake Matching DistanceSnowflake · PHONE SCREENSnowflake interview questions
- LRU Cache with Expiring EntriesPaytm · PHONE SCREENPaytm interview questions
- Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
- Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
- Merge Timestamped Record ListsNuro · PHONE SCREENNuro interview questions
- LRU Cache with TTLPatreon · PHONE SCREEN · ONSITE INTERVIEWPatreon interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Merge k Sorted ListsZS · ONSITE INTERVIEWZS interview questions