Function to check if we reached on of the entry / exit ( corner ) point .
def isCorner ( i , j , M , N ) : NEW_LINE INDENT if ( ( i == 0 and j == 0 ) or ( i == 0 and j == N - 1 ) or ( i == M - 1 and j == N - 1 ) or ( i == M - 1 and j == 0 ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT