HHPE·DSASDE-1Online Assessment
Rotate an Array by K
Problem
Rotate an array to the right by k steps, in place with O(1) extra space.
Example
[1,2,3,4,5,6,7], k=3 -> [5,6,7,1,2,3,4]
Constraints
- 1 ≤ n ≤ 10^5
Approach
Reverse-whole, reverse-first-k, reverse-rest. O(n)/O(1).
added 6 days ago