Arrays medium time O(n) space O(1)
Rotate an Array
To left-rotate by k, reverse the first k elements, reverse the rest, then reverse the whole array. Three in-place reversals rotate with no extra memory.
Left-rotate by k = 3 using three reversals.
1 / 11
Practice
Machine twin: /dsa-viz-v2/rotate-array.json — the full deterministic run as structured data.