Given an integer n, return how many integers x with 0 <= x < 10^n have unique digits, meaning no digit appears more than once in the decimal form of x.
Function Signature
def count_numbers_with_unique_digits(n: int) -> int:
Rules
-
Numbers are written in ordinary decimal form with no leading zeros, so
7
is a one-digit number and
0
itself counts as a number with unique digits.
-
The range is half-open:
10^n
itself is not included.
Constraints
Examples
Input: n = 2
Output: 91
The range [0, 100) holds 100 numbers. The only ones with a repeated digit are 11, 22, 33, 44, 55, 66, 77, 88 and 99, so the answer is 100 - 9 = 91.
Input: n = 0
Output: 1
The range [0, 1) holds only the number 0, which has unique digits.
Input: n = 3
Output: 739
Of the 900 three-digit numbers, 9 * 9 * 8 = 648 have distinct digits. Adding the 91 numbers below 100 from the first example gives 739.