Merge K Sorted Lists
Hard
Linked Lists
Heap
Divide and Conquer
Merge k sorted linked lists into one sorted list.
Input: k lines, each space-separated sorted list
Output: single sorted list
Constraints
See problem-specific constraints. Optimized solution required.
Examples
Example 1:
Input: 1 4 5
1 3 4
2 6
Output:
Example 2:
Input: 1 4 5
1 3 4
2 6
Output:
Hints
Consider a heap approach.
Think about time complexity.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console