#C8131. Right Array Rotation
Right Array Rotation
Right Array Rotation
You are given an array of integers and a non‐negative integer k. Your task is to rotate the array to the right by k steps. In other words, the last k elements of the array should be moved to the beginning while the remaining elements are shifted to the right.
For example, if you have an array [1, 2, 3, 4, 5]
and k is 2, the rotated array will be [4, 5, 1, 2, 3]
.
The input will contain multiple test cases. You need to read the test cases from standard input and output the rotated arrays to standard output.
Note: If k is greater than the length of the array, rotate the array by k mod n steps where n is the number of elements in the array. The rotation formula in LaTeX is: \(a'_{i} = a_{(i - k + n) \mod n}\).
inputFormat
The first line of input contains an integer T representing the number of test cases. Each test case consists of two lines. The first line contains two integers n and k, where n is the number of elements in the array and k is the number of rotations. The second line contains n space-separated integers representing the array elements.
outputFormat
For each test case, output a single line containing the rotated array. Each number should be separated by a single space.## sample
2
5 2
1 2 3 4 5
3 1
7 8 9
4 5 1 2 3
9 7 8
</p>