24 · Heaps & Priority Queues

#23 Merge k Sorted Lists

Hardsolve on LeetCode ↗

frequently reported atNVIDIAMetaOracleAmazonByteDance / TikTokApple

the problem

In plain words

Merge k sorted linked lists into one sorted linked list and return its head.

in lists = [[1,4,5],[1,3,4],[2,6]]

out [1,1,2,3,4,4,5,6]

in lists = []

out []

in lists = [[]]

out []

  • 0 ≤ k ≤ 10⁴
  • 0 ≤ lists[i].length ≤ 500
  • -10⁴ ≤ value ≤ 10⁴
  • Each list is sorted; total nodes ≤ 10⁴

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #21
      Merge Two Sorted Lists
      Easyin Linked Lists
    2. #148
      Sort List
      Mediumin Sorting
    3. #373
    4. #632