Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Merge k Sorted Lists

Hard
heaplinked-listdivide-and-conquer

Merge k sorted linked lists into one sorted linked list and return it.

Input

  • Line 1: integer k
  • Next k lines: each list's values in order (a line may be empty)

Output: the merged list's values, space-separated.

Example 1
Input:
3
1 4 5
1 3 4
2 6
Output:
1 1 2 3 4 4 5 6
Example 2
Input:
1
Output:

Constraints

  • 0 ≤ k ≤ 10^4
  • Total nodes ≤ 10^4; each list sorted ascending.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.