left [ j ] [ j ] , right [ i ] [ j ] , top [ i ] [ j ] and bottom [ i ] [ j ] store maximum number of consecutive 1 's present to the left,  right, top and bottom of mat[i][j]  including cell(i, j) respectively
let left = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { left [ i ] = new Array ( N ) ; } let right = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { right [ i ] = new Array ( N ) ; } let top = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { top [ i ] = new Array ( N ) ; } let bottom = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { bottom [ i ] = new Array ( N ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { left [ i ] [ j ] = 0 ; right [ i ] [ j ] = 0 ; top [ i ] [ j ] = 0 ; bottom [ i ] [ j ] = 0 ; } }