GitHub Viewer
/*
Title: Array Rotation
Problem statement
You are given an array A of size N.
You are also given an integer X and a direction DIR. You need to rotate the array A by X positions
in the direction specified by DIR.
DIR can be:
'LEFT': Rotate the array to the left by X positions.
'RIGHT': Rotate the array to the right by X positions.
Return the resulting rotated array.
For example:
Input :
A = [6, 2, 6, 1], X = 1, DIR = ‘LEFT’
Output :
2 6 1 6
Explanation: Rotate array ‘A’ to the left one time.
[6, 2, 6, 1] => [2, 6, 1, 6]
Detailed explanation ( Input/output format, Notes, Images )
Input Format:
First-line contains 'T,' denoting the number of Test cases.
For each Test case:
The first line contains two integers, ‘N', ‘X’, and the string ‘DIR’.
The second line has ‘N’ integers denoting the array ‘A’.
Output Format:-
You must return the rotated array.
Note:-
You don’t need to print anything. Just implement the given function.
Constraints :
1 > n >> x >> dir;
int array[n];
for(int i = 0; i < n; i++) {
cin >> array[i];
}
RotateArray(array, n, x, dir);
for(int i = 0; i < n; i++) {
cout