All problems
Union of Sorted Arrays
Problem
Merge two sorted arrays into their sorted union without duplicates.
Advance two pointers, always taking the smaller current value, and skip a value when it equals the last one appended. Both inputs are sorted in non-decreasing order.
Return the union as a sorted list of unique values.
Hint
Skip a value whenever it matches the last element already in the output.
Test cases
case 1
in: [[1,2,3],[2,3,4]]
expected: [1,2,3,4]
case 2
in: [[],[]]
expected: []
case 3
in: [[1,1,2],[2,3]]
expected: [1,2,3]
case 4
in: [[-3,0],[0,5]]
expected: [-3,0,5]
Starter codePython
def union_sorted(a, b):
# Your code here
pass4 test cases · run your code against them in the editor