Start learning free

LESSON 346 OF 673 · TWO POINTERS

Merge two sorted arrays

Practice O(n + m)

Given two sorted lists of integers, merge them into one sorted list 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 lists.


STEP 1 OF 10
    Ctrl + Enter to check