Count Numbers with Unique Digits

Given a non-negative integer n, return how many numbers in the range [0, 10^n) have all digits unique. Pattern focus: Digit DP. Build numbers digit by digit while tracking which digits are already used.

Input Format

n = number of digits

Output Format

count of numbers with all unique digits in [0, 10^n)

Constraints

  • 0 <= n <= 10

Examples

Example 1:

Input:

n = 0

Output:

1

Explanation:

Only the number 0 is in the range [0, 1).

Example 2:

Input:

n = 1

Output:

10

Explanation:

The numbers 0 through 9 all have unique digits.

Example 3:

Input:

n = 2

Output:

91

Explanation:

There are 91 numbers from 0 to 99 with all digits unique.

Loading...
Count Numbers with Unique Digits - Dp Advanced