Maximum limit upto which we can place digit . If tight is 1 , means number has already become smaller so we can place any digit , otherwise num [ pos ]
limit = 9 if tight else num [ pos ] NEW_LINE for d in range ( limit + 1 ) : NEW_LINE INDENT currF = tight NEW_LINE currEven = even NEW_LINE currOdd = odd NEW_LINE if d < num [ pos ] : NEW_LINE INDENT currF = 1 NEW_LINE DEDENT DEDENT