Last active
August 18, 2016 16:52
-
-
Save ooade/b9d38f1829057650c40fde73766460ef to your computer and use it in GitHub Desktop.
Hackerrank Warmup Challenge - 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 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