Numbers With Repeated Digits
HardMathdigit dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given a positive integer n, count the integers in the range [1, n] whose decimal representation contains **at least one digit that appears more than once**.
For example, 11, 121, and 1000 qualify, while 123 and 9 do not.
n can be up to 10^9, so counting by checking every number is too slow.
Examples
Input: n = 20
Output: 1
Only 11 has a repeated digit.
Input: n = 100
Output: 10
11, 22, 33, 44, 55, 66, 77, 88, 99, and 100.
Input: n = 1000
Output: 262
There are 738 numbers in [1, 1000] with all-distinct digits, leaving 262.
Constraints
- 1 <= n <= 10^9
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.