Count Numbers with Unique Digits - Problem
Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.
A number has unique digits if no digit is repeated in the number. For example, 123 has unique digits but 121 does not.
Input & Output
Example 1 — Small Case
$
Input:
n = 2
›
Output:
91
💡 Note:
Count all numbers from 0 to 99 with unique digits: single digits (0-9) = 10, two-digits with unique digits (10,12,13,...,98) = 81. Total = 10 + 81 = 91
Example 2 — Minimal Case
$
Input:
n = 0
›
Output:
1
💡 Note:
Range is [0, 1), so only number 0 exists, which has unique digits
Example 3 — Larger Case
$
Input:
n = 3
›
Output:
739
💡 Note:
Numbers 0 to 999: 1-digit = 10, 2-digit = 81, 3-digit = 648. Total = 10 + 81 + 648 = 739
Constraints
- 0 ≤ n ≤ 8
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given n=2, find count in range [0, 100)
2
Process
Count by digit length: 1-digit + 2-digit numbers
3
Output
Total count of unique digit numbers
Key Takeaway
🎯 Key Insight: Use permutation formula P(10,k) to count directly instead of checking every number
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code