Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Merge Two Sorted Lists

Easy
linked-listrecursion

Merge two sorted linked lists l1 and l2 into one sorted list by splicing their nodes, and return its head.

Input

  • Line 1: values of l1 (sorted, may be empty)
  • Line 2: values of l2 (sorted, may be empty)

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

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

Output:
Example 3
Input:

0
Output:
0

Constraints

  • 0 ≤ each list's length ≤ 50
  • -100 ≤ node values ≤ 100
Watch a video walkthrough

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