Function checks if a cell is valid i . e it is inside the grid and equal to the key
def is_valid ( x , y , key , input ) : NEW_LINE INDENT if ( x < n and y < m and x >= 0 and y >= 0 ) : NEW_LINE INDENT if ( visited [ x ] [ y ] == 0 and input [ x ] [ y ] == key ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT