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+ . toString ( )
9+ . trim ( )
10+ . split ( "\n" )
11+ . map ( ( line ) => line . split ( "" ) ) ;
12+
13+ function solution ( input ) {
14+ const N = Number ( input [ 0 ] . join ( "" ) ) ;
15+ const friends = input . slice ( 1 ) ;
16+ let maxCount = 0 ;
17+
18+ for ( let i = 0 ; i < N ; i ++ ) {
19+ const visited = Array ( N ) . fill ( false ) ;
20+
21+ for ( let j = 0 ; j < N ; j ++ ) {
22+ if ( i === j ) continue ;
23+
24+ if ( friends [ i ] [ j ] === "Y" ) {
25+ visited [ j ] = true ;
26+ } else {
27+ for ( let k = 0 ; k < N ; k ++ ) {
28+ if ( friends [ i ] [ k ] === "Y" && friends [ k ] [ j ] === "Y" ) {
29+ visited [ j ] = true ;
30+ break ;
31+ }
32+ }
33+ }
34+ }
35+
36+ const count = visited . filter ( Boolean ) . length ;
37+ maxCount = Math . max ( maxCount , count ) ;
38+ }
39+
40+ return maxCount ;
41+ }
42+
43+ console . log ( solution ( input ) ) ;
You can’t perform that action at this time.
0 commit comments