Skip to content

Instantly share code, notes, and snippets.

@rakibulalam
Last active May 22, 2020 13:05
Show Gist options
  • Save rakibulalam/eddebb0636642789a9fcf34e36b61f8c to your computer and use it in GitHub Desktop.
Save rakibulalam/eddebb0636642789a9fcf34e36b61f8c to your computer and use it in GitHub Desktop.
Left Rotation Hacker Rank
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.replace(/\s*$/, '')
.split('\n')
.map(str => str.replace(/\s*$/, ''));
main();
});
function readLine() {
return inputString[currentLine++];
}
function leftRotation(a, n, d) {
const arr = [];
for (let i = 0; i < n; i++) {
arr.splice(((i + n - d) % n), 0, a[i]);
}
console.log(arr.join(' '));
}
function main() {
const nd = readLine().split(' ');
const n = parseInt(nd[0], 10);
const d = parseInt(nd[1], 10);
const a = readLine().split(' ').map(aTemp => parseInt(aTemp, 10));
leftRotation(a, n, d)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment