Perform each query on the original array only i.e. every output should be according to the original order of elements.
Let the array be [1, 2, 3, 4, 5, 6] and the queries be {2, 4, 1}. For every query, we’ll perform the required number of left rotations on the array.
For the first query, rotate the given array to the left by 2 elements, so the resultant array is: [3, 4, 5, 6, 1, 2].
For the second query, rotate the given array to the left by 4 elements, so the resultant array is: [5, 6, 1, 2, 3, 4].
For the third query, rotate the given array to the left by 1 element, so the resultant array is: [2, 3, 4, 5, 6, 1].
The very first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of every test case contains two space-separated integers ‘N’ and ‘Q’ denoting the number of elements present in the array and the number of queries to be performed on the given array, respectively.
The second line of every test case contains ‘N’ space-separated integers denoting the elements present in the array.
The third line of every test case contains ‘Q’ space-separated integers denoting the queries.
For every query of each test case, return ‘N’ space-separated integers which denote the resultant array after performing the rotation.
You don't need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 1000
1 <= Q <= 100
0 <= Queries[i] <= 10^5
-10^5 <= Array[i] <= 10^5
Where 'Queries[i]' denotes the extent to which the array in each query needs to be rotated and 'Array[i]' denotes the array element.
Time limit: 1 sec
Missing Number
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End