Function to check if we reached on of the entry / exit ( corner ) point .
bool isCorner ( int i , int j , int M , int N ) { if ( ( i == 0 && j == 0 ) || ( i == 0 && j == N - 1 ) || ( i == M - 1 && j == N - 1 ) || ( i == M - 1 && j == 0 ) ) return true ; return false ; }