Trains the technique from
LeetCode 2376Count Special IntegersThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Serials are stamped as plain whole numbers with no leading zeros.
A serial is clean when no digit appears in it more than once.
Given n, return how many clean serials there are from 1 up to n inclusive.
Example 1
Every serial of one, two or three digits with no repeat counts, which is 9 plus 81 plus 648, and then the four-digit serials up to 4321 with no repeat add a further 1080.
Example 2
The nine single-digit serials are all clean, and of the ninety two-digit serials only the nine doubled ones are not. Neither 100 nor 101 is clean, so the count stops at 90.
Example 3
A single digit cannot repeat, so all nine serials are clean.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_special_numbers(n: int) -> int:public int countSpecialNumbers(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.