Reported July 2026
Oracleheap priority queue

Merge k Sorted Lists

Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Oracle OA. Under 2s to a working solution.
Founder's read

Oracle reported Merge k Sorted Lists in July 2026, and the trap isn't the merge. It's the empty input. lists = [] and lists = [[]] both return an empty list, and a naive solution that grabs lists[0] or pushes null heads onto a heap will crash on them. The real pattern is a min-heap over the list heads, or pairwise divide and conquer merging. If you know it cold, this is a ten-minute problem. If you blank, StealthCoder runs invisibly during the live OA and gives you the solution so one bad moment doesn't sink the attempt.

The problem

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[]) → ListNode

Examples
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 -> 6
Merging 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.length
0 <= k <= 10^4
0 <= 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].length values does not exceed 10^4.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: you only ever need the smallest current head across all k lists. Push each non-null head into a min-heap keyed by value, pop the smallest, append it to a dummy-headed result, then push that node's next if it exists. That's O(N log k) where N is the total node count. The alternative is divide and conquer: merge lists in pairs until one remains, same complexity, no heap needed. Pitfalls are concrete. Skip null heads before pushing, or comparisons blow up. Handle k = 0 up front. In languages where heap ties compare the node objects, add an index tiebreaker so equal values don't throw. Don't concatenate everything and sort unless you're fine with extra space and ignoring the linked structure. If the heap tiebreaker or pointer wiring slips under pressure, StealthCoder is the hedge on the live OA, reading the problem and handing you a clean version.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Merge k Sorted Lists 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

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 Oracle's OA.

Oracle reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge k Sorted Lists FAQ

How hard is Merge k Sorted Lists really?+

It's a LeetCode hard by label, but it's easier than it looks. If you can merge two sorted lists, you can do this. The only new idea is a min-heap or pairwise merging. Most failures come from edge cases, not the algorithm.

What's the trick for Merge k Sorted Lists?+

Keep a min-heap holding one node from each non-empty list. Pop the smallest, attach it to your result, push its next node. Repeat until the heap is empty. A dummy head node keeps the pointer logic clean and avoids special-casing the first node.

Which edge cases break a naive solution here?+

Two matter most: lists = [] and lists = [[]]. Both must return an empty list. Also watch for null heads mixed in with real ones. Filter nulls before pushing to the heap, and return null early when there's nothing to merge.

Heap or divide and conquer, which should I write?+

Either gets O(N log k). The heap is more direct if your language has a priority queue. Divide and conquer reuses a two-list merge and avoids tie-comparison issues with node objects. Pick whichever you can write without looking anything up.

How do I prepare for this in 48 hours?+

Write the two-list merge from memory first. Then write the heap version once, testing against [], [[]], and the three-list example. Then do divide and conquer once. That's enough. Focus on getting the null handling right rather than memorizing variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Oracle.

OA at Oracle?
Invisible during screen share
Get it