
Input: 'a' = 5, 'arr' = [1, 2, 3, 4, 5]
Output: [2, 3, 4, 5, 1]
Explanation: We moved the 2nd element to the 1st position, and 3rd element to the 2nd position, and 4th element to the 3rd position, and the 5th element to the 4th position, and move the 1st element to the 5th position.
The first line will contain a single integer 'n', the size of the array ‘arr’
The second line will contain ‘n’ integers representing the array elements.
The output contains all elements of the rotated array separated by space.
You don't need to print anything. It has already been taken care of. Just implement the given function.
We can create a temporary array ‘rotatedArr’and store the ith element from 1 to N-1 from ‘ARR’ to i-1 the position in ‘rotatedArr’ and we store 0th element from ‘ARR’ to (n-1)th position in ‘rotatedArr’ and return ‘rotatedArr’.
We can store the first element of ‘arr’ in a temporary variable ‘temp’ and move each element ‘i’ where 1<= i <= ‘n’-1 to (i-1)th place formally speaking arr[i] = arr[i+1]. And replace (n-1)th element with the value of ‘temp’. In this way, our array will be rotated without using any extra space.