Created
August 4, 2016 12:48
-
-
Save CraigRodrigues/8796843d86dd61423b155f554e9e8ff5 to your computer and use it in GitHub Desktop.
HackerRank - Algorithms - Warmup - Circular Array Rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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])]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's actually unnecessary to make a second array.