Skip to content

Commit 7f65262

Browse files
committed
larrys array
1 parent 93587e9 commit 7f65262

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

larrys-array.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
process.stdin.resume();
6+
process.stdin.setEncoding('utf-8');
7+
8+
let inputString = '';
9+
let currentLine = 0;
10+
11+
process.stdin.on('data', inputStdin => {
12+
inputString += inputStdin;
13+
});
14+
15+
process.stdin.on('end', _ => {
16+
inputString = inputString.replace(/\s*$/, '')
17+
.split('\n')
18+
.map(str => str.replace(/\s*$/, ''));
19+
20+
main();
21+
});
22+
23+
function readLine() {
24+
return inputString[currentLine++];
25+
}
26+
27+
// Complete the larrysArray function below.
28+
function larrysArray(A) {
29+
let count = 0;
30+
for (let i = 1; i < A.length; i++) {
31+
for (let k = 0; k < i; k++) {
32+
if (A[k] > A[i]) count++;
33+
}
34+
}
35+
return count % 2 === 0 ? "YES": "NO";
36+
}
37+
38+
function main() {
39+
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
40+
41+
const t = parseInt(readLine(), 10);
42+
43+
for (let tItr = 0; tItr < t; tItr++) {
44+
const n = parseInt(readLine(), 10);
45+
46+
const A = readLine().split(' ').map(ATemp => parseInt(ATemp, 10));
47+
48+
let result = larrysArray(A);
49+
50+
ws.write(result + "\n");
51+
}
52+
53+
ws.end();
54+
}

0 commit comments

Comments
 (0)