• + 2 comments

    This code is actually quite efficient. So for the following values, n=5 (number of elements in the array), d=2 (number of rotations)and assuming i goes from 0-4. (i + n - d)%n with the iteration of i from 0-4: (0+5-2)%5=3 (1+5-2)%5=4 . . . (4+5-2)%5=2 So essentially, you are changing the locations of the elements in the array. How the "%" works is that it takes the remainder. So for example, 1%7=1 since 1 cannot be divided by 7 which means 1 is the remainder.