Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Merge Two Sorted Arrays

Easy
two-pointersarraysorting

Given two integer arrays nums1 and nums2, each sorted in non-decreasing order, merge them into a single sorted array and return it.

Input

  • Line 1: space-separated integers nums1 (may be empty)
  • Line 2: space-separated integers nums2 (may be empty)

Output: the merged sorted array, space-separated.

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

1
Output:
1

Constraints

  • 0 ≤ nums1.length, nums2.length ≤ 200
  • -10^9 ≤ values ≤ 10^9
Watch a video walkthrough

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