You are viewing a single comment's thread. Return to all comments →
You deal with lengthOfArray < shiftAmount by using:
shiftAmount = shiftAmount % lengthOfArray;
If the array length is 4, and you're shifting 6, then you really just want to shift 2.
The constraints say that shiftAmount will always be >= 1, so you don't have to worry about negative numbers.
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 →
You deal with lengthOfArray < shiftAmount by using:
If the array length is 4, and you're shifting 6, then you really just want to shift 2.
The constraints say that shiftAmount will always be >= 1, so you don't have to worry about negative numbers.