Function to check if the index is within the matrix boundary .
def isValid ( i , j , M , N ) : NEW_LINE INDENT if ( i < 0 or i >= M or j < 0 or j >= N ) : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT