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