Given an integer n, you need to find how many positive integers in the range [1, n] contain at least one repeated digit.
For example, the number 1223 has repeated digits (the digit '2' appears twice), while 1234 has all unique digits.
Goal: Count all numbers from 1 to n that have duplicate digits.
Input: A positive integer n
Output: The count of numbers with at least one repeated digit
Note: This is a challenging combinatorics problem that can be solved by calculating the complement - finding numbers with all unique digits and subtracting from the total.
Input & Output
Visualization
Time & Space Complexity
We only process each digit position of n once, so time is proportional to number of digits in n
Only using a few variables for calculations, no additional data structures needed
Constraints
- 1 β€ n β€ 109
- n is a positive integer
- The answer fits in a 32-bit signed integer