File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments