Check if absolute difference between prev digit and current digit is 1
if ( abs ( prevDigit - curDigit ) != 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT prevDigit = curDigit NEW_LINE n //= 10 NEW_LINE return True NEW_LINE