You are viewing a single comment's thread. Return to all comments →
This answer is true for right shifting, for left shifting test cases are failing.
for(int i = 0; i < lengthOfArray; i++){ int newLocation = (i + (lengthOfArray - shiftAmount)) % lengthOfArray; a[newLocation] = in.nextInt(); } This is correct answer for left shifting.
for(int i = 0; i < lengthOfArray; i++){ int newLocation = (i + (lengthOfArray - shiftAmount)) % lengthOfArray; a[newLocation] = in.nextInt(); }
This is correct answer for left shifting.
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 →
This answer is true for right shifting, for left shifting test cases are failing.