Merge K Sorted Lists
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.

30:00

Merge K Sorted Lists
hard
Topics
Companies

You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it.

Example 1:
Input: [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Constraints:
  • k==lists.lengthk == \text{lists.length}

  • 0k1040 \leq k \leq 10^4

  • 0lists[i].length5000 \leq \text{lists}[i].\text{length} \leq 500

  • 104lists[i][j]104-10^4 \leq \text{lists}[i][j] \leq 10^4

  • lists[i] is sorted in ascending order.

  • The sum of lists[i].length will not exceed 10410^4.

Input
arr =[[1,4,5],[1,3,4],[2,6]]

Init lists and heap

List 1

1

4

5

List 2

1

3

4

List 3

2

6

Min Heap (Values)

1

1

2

Result

Null

Variables
No variables to display
DepthFunction Call
Stack empty
0/25