Rotate array by K steps
Simplify Rotation Amount
For an array of sized instead of doing rotation
we can simply do rotation
If we rotate steps to right we need to start reading the rotated array from the last elements.
If we rotate steps to left we need to start reading the rotated array after skipping elements from start
Rotation
Complexity
Time complexity :
We iterate the whole array only once
Space complexity :
No extra space is needed
Code
Last updated