Union of two sorted arrays

Question

Suppose you're given two sorted arrays (a and b) of lengths m and n. Write a function to return the union of the two arrays (preserving duplicate values). You may assume that the first array, a, has size equal to m+n, meaning it has enough space to hold additional elements from array b. For example:

  • a = [1,2,6,0,0,0], m = 3, b = [2,5,6], n = 3 should be returned as [1, 2, 2, 5, 6, 6]

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now