Arrays: Left Rotation

  • + 2 comments
    new_index = (i + no_of_left_rotation) % length_of_array;
    

    seems incorrect. You will see the problem if you test, for example [1,2,3,4,5] and k = 2 .

    I guess would be better:

    new_index = (i + (lengthOfArray - no_of_left_rotation)) % lengthOfArray;