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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Linked Lists problems