Arrays: Left Rotation

  • + 0 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.