Problem · Linked List
Merge k Sorted Lists
Learn this problemProblem 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 problems
- Implement a Queue Using Two StacksPHONE SCREEN · Seen Jul 2026
- First Balanced Removal IndexOA · Seen Dec 2025
- Find Circle NumberSeen Oct 2024
- Create Lexicographically Largest PermutationSeen Sep 2024
- Array Reduction 1Seen Feb 2024
- Balancing ParenthesesSeen Feb 2024
- Merge 2 ArraysSeen Feb 2024
- Last and Second-LastSeen Feb 2024