Hard · Linked Lists

Merge K Sorted Lists

Given an array of k linked lists, each sorted in ascending order, merge all of their nodes into one ascending linked list and return its head (null when there are no nodes).

Examples

Example 1

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

Output: 1→1→2→3→4→4→5→6

Example 2

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

Output: 1→2→3→4→5→6→7

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Linked Lists problems