• + 2 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.