hardMath / GeometryPure DSA~40 min
Count IDs That Repeat a Digit
An ID generator hands out numbers from 1 to n. Compliance needs to know how many of those IDs contain at least one repeated digit (which weakens uniqueness guarantees).
Problem
Given a positive integer n, return the count of integers in the range [1, n] that have at least one repeated digit.
Input
A positive integer n.
Output
An integer: how many values in [1, n] contain a repeated digit.
Constraints
- 1 <= n <= 10^9
Examples
Example 1
Input
n = 20
Output
1
Only 11 has a repeated digit in [1,20].
Example 2
Input
n = 100
Output
10
11,22,33,...,99,100 — ten numbers repeat a digit.