You are viewing a single comment's thread. Return to all comments →
The problem is that k may be greater than n. So you have you write
k = k%n
For example, if we have to make k = 6 rotations in a list containing 3 elements.
It is the same as making 0 rotation. Since every element will be in the
same position after 6 rotations.
k%3 = 0 when k=6
k%3 = 2 when k=5
2 rotations are the same as making 5 rotations.
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
The problem is that k may be greater than n. So you have you write
k = k%n
For example, if we have to make k = 6 rotations in a list containing 3 elements.
It is the same as making 0 rotation. Since every element will be in the
same position after 6 rotations.
k%3 = 0 when k=6
k%3 = 2 when k=5
2 rotations are the same as making 5 rotations.