← Back

β­• Twin Realm Overlap

Find Intersection of Sorted Arrays

Pointer i

0

Pointer j

0

Matches

0

Comparisons

0

Step

0
πŸ’— Realm A
πŸ’™ Realm B
✨ Intersection (Common Elements)
Generate two sorted arrays to find their intersection!

πŸ“– Intersection of Sorted Arrays

Two Pointers: Compare elements at i and j

β€’ If A[i] == B[j]: Found match! Add to result, advance both

β€’ If A[i] < B[j]: Advance i (A[i] can't match anything)

β€’ If A[i] > B[j]: Advance j

Time: O(n + m)