"""
Given an array of integers, rotate the array by 'N' elements.

Given an array of integers, rotate the array by NNN elements where NNN is an integer:

    For positive values of NNN, perform a right rotation.
    For negative values of NNN, perform a left rotation.

Make sure you make changes to the original array.
"""


def reverse_array(arr, start, end):
    while start < end:
        temp = arr[start]
        arr[start] = arr[end]
        arr[end] = temp
        start += 1
        end -= 1


def rotate_array(arr, n):
    length = len(arr)

    # Let's normalize rotations
    # if n > array size or n is negative.
    n = n % length
    print(n)
    if n < 0:
        # calculate the positive rotations needed.
        n = n + length
        print(n)
    # Let's partition the array based on rotations 'n'.
    # For example: 1, 2, 3, 4, 5 where n = 2.
    # -> 5, 4, 3, 2, 1
    # -> 4, 5, 3, 2, 1
    # -> 4, 5, 1, 2, 3

    reverse_array(arr, 0, length - 1)
    reverse_array(arr, 0, n - 1)
    reverse_array(arr, n, length - 1)
