Skip to content

Instantly share code, notes, and snippets.

@ooade
Created October 7, 2016 06:35
Show Gist options
  • Save ooade/a23a3c87b40f949e043387e971e00181 to your computer and use it in GitHub Desktop.
Save ooade/a23a3c87b40f949e043387e971e00181 to your computer and use it in GitHub Desktop.
Hackerrank (Arrays: Left Rotation)
function main() {
var n_temp = readLine().split(' ');
var n = parseInt(n_temp[0]);
var k = parseInt(n_temp[1]);
a = readLine().split(' ');
a = a.map(Number);
var i = k;
if (k > n) {
i = k % n;
}
console.log([a.splice(i, n).join(' ')].concat(a).join(' '));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment