-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypted_sequence.js
More file actions
61 lines (51 loc) · 1.38 KB
/
Copy pathencrypted_sequence.js
File metadata and controls
61 lines (51 loc) · 1.38 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Time Complexity => O()
// Space Complexity => O()
function runProgram(input){
let input_arr = input.trim().split("\n")
for(let i = 1; i < input_arr.length; i += 2){
var n = Number(input_arr[i])
var array = input_arr[i+1].trim().split(" ")
var mid = Math.ceil(n/2)
var left = array.slice(0, mid)
var right = array.slice(mid)
// console.log(left)
// console.log(right)
var decrypt = ""
for(var j = 0, k = right.length - 1; j < left.length; j++, k--){
if(left.length == right.length){
decrypt += left[j] + " "
decrypt += right[k] + " "
}
else{
if(j == left.length -1){
decrypt += left[j] + " "
}
else{
decrypt += left[j] + " "
decrypt += right[k] + " "
}
}
}
console.log(decrypt.trim())
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/,"")
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/,"")
runProgram(read);
process.exit(0);
});
runProgram(`2
5
1 3 5 4 2
6
1 3 5 6 4 2`)