Arrays: Left Rotation

  • + 2 comments

    What if lengthOfArray < shiftAmount? I think you should use abs value

    • + 0 comments

      there is a constraint that says there wont be negatives so it should be fine. if it wasn't given then use abs.

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