You are viewing a single comment's thread. Return to all 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;
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays: Left Rotation
You are viewing a single comment's thread. Return to all comments →
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: