-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctci-array-left-rotation.js
More file actions
42 lines (35 loc) · 930 Bytes
/
Copy pathctci-array-left-rotation.js
File metadata and controls
42 lines (35 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
function leftShift(arr, k, n) {
let newArray = [];
for (let i = k; i < n; i++) {
newArray.push(arr[i]);
}
for (let i = 0; i < k; i++) {
newArray.push(arr[i]);
}
return newArray;
}
/////////////// ignore above this line ////////////////////
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);
result = leftShift(a, k, n);
console.log(result.join(' '));
}