The patterns behind 60% of array-based interview questions.
Variants
Two pointers walking inward, each capped by the tallest bar behind it. The shorter side is always safe to settle.
Start at the widest pair and move the shorter wall inward. Width only shrinks, so only a taller wall can help.
A slow write pointer trails a fast read pointer. Every non-zero it finds is swapped down to the write slot, in place.
A slow write pointer keeps the last unique value while a fast reader scans ahead. Because the array is sorted, duplicates are always adjacent.
Three pointers partition the array into 0s, 1s and 2s in a single pass: low and high grow inward while mid scans.