Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Created August 4, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/8796843d86dd61423b155f554e9e8ff5 to your computer and use it in GitHub Desktop.
Save CraigRodrigues/8796843d86dd61423b155f554e9e8ff5 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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