Numbers With Repeated Digits - Problem
Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.
For example, if n = 100, numbers like 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 all have repeated digits.
Input & Output
Example 1 — Small Number
$
Input:
n = 20
›
Output:
1
💡 Note:
Only number 11 has repeated digits in range [1, 20]
Example 2 — Medium Number
$
Input:
n = 100
›
Output:
10
💡 Note:
Numbers 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 all have repeated digits
Example 3 — Single Digit
$
Input:
n = 5
›
Output:
0
💡 Note:
Numbers 1, 2, 3, 4, 5 all have unique digits (single digit numbers)
Constraints
- 1 ≤ n ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given integer n = 100
2
Process
Count numbers [1,100] with repeated digits
3
Output
Return count = 10
Key Takeaway
🎯 Key Insight: Count numbers without repeated digits using combinatorics, then subtract from total
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code