File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const input = require ( "fs" )
2+ . readFileSync (
3+ process . platform === "linux"
4+ ? "/dev/stdin"
5+ : require ( "path" ) . join ( __dirname , "input.txt" ) ,
6+ "utf8"
7+ )
8+ . trim ( )
9+ . split ( "\n" ) ;
10+
11+ function solution ( input ) {
12+ let index = 0 ;
13+ const T = Number ( input [ index ++ ] ) ;
14+ const output = [ ] ;
15+
16+ for ( let t = 0 ; t < T ; t ++ ) {
17+ const N = Number ( input [ index ++ ] ) ;
18+ const numbers = [ ] ;
19+
20+ for ( let i = 0 ; i < N ; i ++ ) {
21+ numbers . push ( input [ index ++ ] ) ;
22+ }
23+
24+ numbers . sort ( ) ;
25+
26+ let consistent = true ;
27+ for ( let i = 0 ; i < N - 1 ; i ++ ) {
28+ if ( numbers [ i + 1 ] . startsWith ( numbers [ i ] ) ) {
29+ consistent = false ;
30+ break ;
31+ }
32+ }
33+
34+ output . push ( consistent ? "YES" : "NO" ) ;
35+ }
36+
37+ return output . join ( "\n" ) ;
38+ }
39+
40+ console . log ( solution ( input ) ) ;
Original file line number Diff line number Diff line change 1+ const input = require ( "fs" )
2+ . readFileSync (
3+ process . platform === "linux"
4+ ? "/dev/stdin"
5+ : require ( "path" ) . join ( __dirname , "input.txt" ) ,
6+ "utf8"
7+ )
8+ . trim ( )
9+ . split ( "\n" ) ;
10+
11+ function solution ( input ) {
12+ const N = Number ( input [ 0 ] ) ;
13+ const root = { } ;
14+
15+ for ( let i = 1 ; i <= N ; i ++ ) {
16+ const arr = input [ i ] . split ( " " ) ;
17+ const path = arr . slice ( 1 ) ;
18+
19+ let current = root ;
20+ for ( let food of path ) {
21+ if ( ! current [ food ] ) {
22+ current [ food ] = { } ;
23+ }
24+ current = current [ food ] ;
25+ }
26+ }
27+
28+ function dfs ( node , depth ) {
29+ const keys = Object . keys ( node ) . sort ( ) ;
30+ for ( let key of keys ) {
31+ console . log ( "--" . repeat ( depth ) + key ) ;
32+ dfs ( node [ key ] , depth + 1 ) ;
33+ }
34+ }
35+
36+ dfs ( root , 0 ) ;
37+ }
38+
39+ solution ( input ) ;
You can’t perform that action at this time.
0 commit comments