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
$ left [ $ N ] [ $ N ] = array ( ) ; $ right [ $ N ] [ $ N ] = array ( ) ; $ top [ $ N ] [ $ N ] = array ( ) ; $ bottom [ $ N ] [ $ N ] = array ( ) ;