Created
January 22, 2017 11:46
-
-
Save kirankumaramruthaluri/d73dfba48c2fb7887f6b27b6d453c1e6 to your computer and use it in GitHub Desktop.
Hackerrank : Circular array rotation
This file contains hidden or 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
function main() { | |
var n_temp = readLine().split(' '); | |
var n = parseInt(n_temp[0]); | |
var k = parseInt(n_temp[1]); | |
var q = parseInt(n_temp[2]); | |
a = readLine().split(' '); | |
a = a.map(Number); | |
var rot = k%n; | |
for(var a0 = 0; a0 < q; a0++) { | |
var m = parseInt(readLine()); | |
if (m - rot >= 0) { | |
console.log(a[m - rot]); | |
} else { | |
console.log(a[m - rot + a.length]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment