Similarly , fill row matrix
for ( let i = 0 ; i < n ; i ++ ) { let isEndless = true ; for ( let j = n - 1 ; j >= 0 ; j -- ) { if ( input [ i ] [ j ] == false ) isEndless = false ; row [ i ] [ j ] = isEndless ; } }