Reported September 2024
Skydioheap priority queue

Merge K Sorted Lists

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

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

The structure that makes this one work is a min-heap. Skydio reported Merge K Sorted Lists in September 2024, and if your OA invite is sitting in your inbox, this is the version where the lists come in as plain int arrays. It's the classic merge-k problem with the linked-list wrapper stripped off. You know the idea: always grab the smallest available head. The OA just wants to see you do it in O(N log k) instead of sorting everything. If you blank on the heap mechanics under the clock, StealthCoder runs invisibly on your screen as a safety net for the live assessment.

The problem

You are given k singly linked lists, each sorted in nondecreasing order. For the runner, lists[i] stores the node values of the i-th list from head to tail.
Merge all lists into one sorted linked list and return its values from head to tail. Reusing existing nodes or constructing an equivalent merged list are both acceptable.

Function
mergeKSortedLists(lists: int[][]) → int[]

Examples
Example 1
lists = [[1,4,5],[1,3,4],[2,6]]
return = [1,1,2,3,4,4,5,6]
Taking the smallest available head at each step produces the complete nondecreasing merge.
Example 2
lists = []
return = []
With no input lists, the merged list is empty.
Example 3
lists = [[],[-2,0,7],[]]
return = [-2,0,7]
Empty lists contribute no nodes, so the one nonempty list is returned unchanged in value order.

Constraints
0 <= lists.length <= 10000.
0 <= lists[i].length <= 500.
The total number of values across all lists is at most 100000.
-10^9 <= lists[i][j] <= 10^9.
Every lists[i] is sorted in nondecreasing order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a min-heap holding one entry per list: the current value, the list index, and the position in that list. Pop the smallest, append it to the output, then push the next element from that same list if one exists. Each of the N total values gets pushed and popped once, so you get O(N log k). Pitfalls: skipping empty lists when seeding the heap, and forgetting that lists can be empty entirely (the lists = [] case returns []). Don't push all values and sort. That's O(N log N) and it works, but it misses the point. Also watch your tuple comparison so ties don't break on something unorderable. An alternative is pairwise divide and conquer merging, which hits the same complexity. If the heap code slips away mid-assessment, StealthCoder is the hedge that gives you a working solution on screen without the proctor seeing anything.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

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

Skydio reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. 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 a well-known one. Once you see the min-heap idea, the code is about 15 lines. The difficulty is remembering the heap setup and edge cases, not inventing anything new.

What's the trick for the Skydio version?+

Keep a min-heap with one entry per nonempty list, storing value, list index, and element index. Pop the smallest, append it, push that list's next element. Total work is O(N log k) across at most 100000 values.

Can I just concatenate and sort?+

It would pass correctness and probably the constraints, since N is at most 100000. But it ignores that the lists are already sorted. If the grader or reviewer cares about approach, the heap or divide and conquer is the expected answer.

What edge cases should I test?+

Test lists = [] returning [], lists with empty inner arrays like [[],[-2,0,7],[]], duplicate values across lists, negative values down to -10^9, and a single list. Up to 10000 lists means seeding the heap must skip empties cleanly.

How do I prepare in 48 hours?+

Write the heap solution from scratch twice, then write the divide and conquer pairwise merge once. Know your language's heap API and how it compares tuples. That covers this problem and most merge-style variants you could see.

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

OA at Skydio?
Invisible during screen share
Get it