Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HackerRank - Algorithms - Warmup - Circular Array Rotation
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
// https://www.hackerrank.com/challenges/circular-array-rotation
int main(void)
{
int n, k, q;
scanf("%d %d %d", &n, &k, &q);
int arr[n];
for(int i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
int toprint[q];
for(int i = 0; i < q; i++){
scanf("%d",&toprint[i]);
}
int arr2[n];
for(int i = 0; i < n; i++){
arr2[(i+k)%n] = arr[i];
}
for(int i = 0; i < q; i++){
printf("%d\n", arr2[(toprint[i])]);
}
}
@CraigRodrigues

This comment has been minimized.

Copy link
Owner Author

commented Aug 4, 2016

It's actually unnecessary to make a second array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.