Start learning free

LESSON 340 OF 667 · TWO POINTERS

Merge two sorted arrays

Practice O(n + m)

Given two sorted vectors of integers, merge them into one sorted vector containing all numbers

Example:

Input: first =[1, 4, 8],
       second = [1, 3, 4, 17]

Output: [1, 1, 3, 4, 4, 8, 17]
			

Note:

Your algorithm should run in O(n + m) time and use O(n + m) extra space, where n and m are the lengths of the two vectors.


STEP 1 OF 10
    Ctrl + Enter to check