There is a task with hackerrank in short, you need to make a shift to the right by K, a certain number of times N (it is better to read the condition on hr because I very stupidly explained: C)
I got something like that but this is understandably wrong
var massiv = [1,2,3] func shift(var arr: [Int], much: Int) -> [Int] { for _ in 0..<much { var z = arr.removeFirst() arr.append(z) } return arr } shift(massiv, much: 2)
Task text:
John Watson wants to check out Sherlock Holmes. He gave him an array of A0, A1 ... AN-1. Performed some array transformation, and then asked Sherlock Q questions. Sherlock feels that the transformation that John applied is called a cyclic right shift by K. A cyclic right shift by 1 converts the array A0, A1 ... AN-1 to AN-1, A0 ... AN-2. John applied the unit shift K times.
Help Sherlock answer the questions. Each question is described by an integer X, in response to a question, Sherlock must write out the element AX of the transformed array.
Input The first line contains three integers, space-separated, N, K, and Q. The next line contains N integers, space-separated, array A. Each of the following Q lines contains an integer X, a description of the current question.
Output For each question, output the corresponding element of the converted array.
Restrictions
1 <= N <= 105
1 <= A [i] <= 105
1 <= K <= 105
1 <= Q <= 500
0 <= X <= N-1Sample Input # 00
3 2 3
1 2 3
0
one
2Sample Output # 00
2
3
one
Explanation of examples
After the first cyclic shift by 1, the array will become: 3 1 2.
After the second, it will be equal to: 2 3 1.
The 0th element of the array is 2.
The 1st element of the array is 3.
The 2nd element of the array is 1.