Function to find the maximum distance
int maxDistance ( vector < vector < int > > & grid ) { if ( ! grid . size ( ) ) return -1 ; int N = grid . size ( ) ; int INF = 1000000 ; vector < vector < int > > dp ( N , vector < int > ( N , 0 ) ) ; grid [ 0 ] [ 0 ] = grid [ 0 ] [ 0 ] == 1 ? 0 : INF ;