Skip to content

Rotate Array K times ​

Rotate Array K times — LeetCode

Rotate an array to the right by k steps, in place and with O(1) extra space.

Approach ​

Solution was not obvious to me at all. First reverse the whole array. Then reverse from 0 - (k - 1) Then reverse from k - (n - 1)

Remarks ​

Doing it in place is the hardest! Other solutions are easy