I dint know how to initialize circular array
Circular array is same as array.
for(int i=0;i<N;i++)
cin>>arr[i];
now:
- if you want to reach element x positions behind i:
arr[(i-x+N)%N] - if you want to reach element x positions ahead i(not needed in this question):
arr[(i+x)%N]
where N is size of array.
Using the above approach, you can easily solve the problem in O(N*Q) approach.
I made use of a simple observation and solved it in O(N).
Here is my solution.
https://ide.codingblocks.com/s/33762