ArticlesArrays
Rotating an array
Move the front of a contiguous array to the back. A full turn does nothing, so only the remainder matters.
Rotating left by some number of steps moves the front of the array to the back. The list 1, 2, 3, 4 rotated left by one step is 2, 3, 4, 1. Each element slides, and the piece that falls off the front comes back on the end.
Steps can be larger than the length. Rotating by the length itself puts every element back where it started, so whole turns do nothing. Only the remainder matters: steps modulo the length. An empty array stays empty, because there is nowhere to move.
The clear solution allocates a new array and writes each value at its new index. That is a single O(n) pass, and it does not mutate the input. In-place reversal tricks exist. You do not need them to understand the movement. The point is to feel that a contiguous block has to be rewritten when the order changes.