You are viewing a single comment's thread. Return to all comments →
What if lengthOfArray < shiftAmount?
I think you should use abs value
there is a constraint that says there wont be negatives so it should be fine. if it wasn't given then use abs.
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.