Skip to content

Instantly share code, notes, and snippets.

@ooade
Last active August 18, 2016 16:52
Show Gist options
  • Select an option

  • Save ooade/b9d38f1829057650c40fde73766460ef to your computer and use it in GitHub Desktop.

Select an option

Save ooade/b9d38f1829057650c40fde73766460ef to your computer and use it in GitHub Desktop.
Hackerrank Warmup Challenge - Circular Array Rotation
function processData(input) {
let lines = input.split('\n');
let arr = lines[1].split(' ');
let k = lines[0].split(' ')[1]; // No of spins
let n = arr.length;
for (var i = 2, l = lines.length; i < l; i++) { // First two lines are for k, n and arr so let's skip em
let pos = (n + (lines[i] - (k % n))) % n; // This does the magic!
console.log(arr[pos]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment