Arrays: Left Rotation

  • + 95 comments

    With my solution I used modular arithmetic to calculate the position of the each element and placed them as I read from input.

    for(int i = 0; i < lengthOfArray; i++){
        int newLocation = (i + (lengthOfArray - shiftAmount)) % lengthOfArray;
        a[newLocation] = in.nextInt();
    }