← All problems
Rotate Array
Rotate an array to the right by k steps in place with O(1) extra space. For example, [1,2,3,4,5,6,7] with k=3 becomes [5,6,7,1,2,3,4]. k may be larger than the array length.
Complexity
Time O(n), Space O(1)
Common pitfalls
- Forgetting k %= n (k can exceed n)
- Extra array when in-place required
Your solution
Log in to save your code and track progress.