1
2
3
4
5
6
7
[0][1][2][3][4][5][6]
Brute force · rotate by one, k times
▸1repeat k times:2 move the last element to the front, shifting the rest right3return arr
state
- k3
Rotate an array to the right by k steps, in place. k may be larger than the length of the array.
▸1repeat k times:2 move the last element to the front, shifting the rest right3return arr
line 1Shift everything right by one place, 3 times over.