← Back

🔗 Realm Unification

Union of Sorted Arrays (No Duplicates)

Ptr i

0

Ptr j

0

Union Size

0

Skipped

0

Step

0
🟠 Array A
🟢 Array B
🔮 Union (All Unique Elements)
Generate arrays to create their union!

📖 Union of Sorted Arrays

Goal: Combine all unique elements from both arrays

• Compare A[i] and B[j], add smaller to union

• Skip if same as last added (avoid duplicates)

• Handle remaining elements from non-exhausted array

Time: O(n + m)