Read / Write Heads
Two pointers walk the same array in the same direction: a read head scans every element, and a write head marks where the next kept element belongs. Whatever the read head decides to keep gets written at the write head, which only then advances - so the prefix [0, write) is always the compacted answer.
Remove Elements
27. Remove Element
Easy·
2 Approaches
Overwrite
O(N)O(1)
Swap to Back
O(N)O(1)
FIG. 27 REMOVE ELEMENT● INTERACTIVE
visualization loads as you reach it
283. Move Zeroes
Easy·
283Move Zeroes
2 Approaches
Compact then Zero-fill
O(2N)O(1)
Swap Zeroes Back
O(N)O(1)
FIG. 283 MOVE ZEROES● INTERACTIVE
visualization loads as you reach it
1119. Remove Vowels from a String
Easy·
Read / Write Heads
O(N)O(N)
FIG. 1119 REMOVE VOWELS FROM A STRING● INTERACTIVE
visualization loads as you reach it
Remove Elements from Sorted Array
80. Remove Duplicates from Sorted Array II
Medium·
Generic k = 2
O(N)O(1)
FIG. 80 REMOVE DUPLICATES FROM SORTED ARRAY II● INTERACTIVE
visualization loads as you reach it
26. Remove Duplicates from Sorted Array
Easy·
Generic k = 1
O(N)O(1)
FIG. 26 REMOVE DUPLICATES FROM SORTED ARRAY● INTERACTIVE
visualization loads as you reach it
Sort the Array
922. Sort Array By Parity II
Easy·
Read / Write Heads (parity)
O(N)O(1)
FIG. 922 SORT ARRAY BY PARITY II● INTERACTIVE
visualization loads as you reach it