As per the solution you have provided -> why are we calculating the mod “Can you please explain the logic?” . can we use the juggling algo ?
We are using mod because if the rotation values is more than size of array so there will less extra computation. If you dont’t use mod and rotation value is more than at some point during rotation you will have same values of arrays that you started with earlier
Suppose we begin the rotation, now after few elements, most likely when we are the end of the array then the B value would exceed the array length.
Thus to reach the beginning of the array we need this mod function.
When we use the mod function we are reducing so much of trouble
- We are using the array as a cyclic one.
- We are ensuring that the rotation which takes place is feasible, for eg if the rotation is larger than the array size, then also this would work.