Merge Multiple Sorted Linked Lists - aloalgo

Merge Multiple Sorted Linked Lists

Hard

You are given a list of k linked lists.

Your task is to merge all the linked lists into one single sorted linked list.

You may assume that:

  • Each linked list in the input list is sorted in ascending order.

Return the head of the merged sorted linked list.

Example 1

Input
[
  1 → 4 → null,
  2 → 3 → null
]
Output
1 → 2 → 3 → 4 → null
Explanation:

Merging two sorted lists results in a sorted linked list

Example 2

Input
[
  1 → 3 → null,
  2 → 5 → 5 → null,
  4 → null
]
Output
1 → 2 → 3 → 4 → 5 → 5 → null
Explanation:

Merging multiple sorted lists results in a sorted linked list

Example 3

Input
[
  1 → 5 → null,
  None,
  2 → 4 → null
]
Output
1 → 2 → 4 → 5 → null
Explanation:

Merging empty lists with sorted lists results in a sorted list

Loading...
Input
[
  1 → 4 → null,
  2 → 3 → null
]
Output
1 → 2 → 3 → 4 → null

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!