-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.java
36 lines (31 loc) · 999 Bytes
/
solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // number of elements in the integer array
int k = sc.nextInt()%n;// because every n rotations we receive the same array
int q = sc.nextInt(); // number of queries
int[] a = new int[n];
for(int i=0; i < n; i++){
a[i] = sc.nextInt();
}
//Run each query q
for(int i = 0; i < q; i++){
int m = sc.nextInt(); // index of an element in array to return
//Checks if array wrap occurs
if(m-k >=0)
{
System.out.println(a[m-k]);
}
else
{
//if array rap occurs then
System.out.println(a[n+(m-k)]);
}
}
}
}