Input: a[] = [9, 7, 2, 3, 6], b[] = [7, 4, 8, 0, 1]
Output: [9, 7, 6, 4, 8]
Explanation: Start with elements from a[]: 9, 7, 2, 3, 6. Remove duplicates later if they appear again in b[] (7 is already taken). Now consider b[]: skip 7 (already added), then take 4 and 8. Stop once we have 5 unique elements.
Input: a[] = [6, 7, 5, 3], b[] = [5, 6, 2, 9]
Output: [6, 7, 5, 9]
Explanation: Start with elements from a[]: 6, 7, 5, 3. We now have 4 elements, but we skip 3 to allow space for unique ones from b[]. From b[], skip 5 and 6 (already taken), then take 9. Now we have 4 unique elements in total.