Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Merge k Sorted Lists

Hard

Topics
Linked ListHeapDivide and ConquerMerge Sort

You are given an array of k sorted linked lists. Merge them into one sorted list and return its head.

Example 1

Input:  lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]

Example 2

Input:  lists = []
Output: []

Constraints

  • 0 <= k <= 10^4
  • 0 <= list length <= 500
  • Each list is sorted non-decreasing.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access