Count Numbers with Unique Digits
Real-world version: Clean Crate StampsThe statement here is our own: the same inputs, outputs and technique.
A depot stamps its crates with the whole numbers from 0 up to but not including 10^n. A stamp is clean when no digit occurs twice in it, written the ordinary way with no leading zeros: 9, 40 and 907 are clean, while 11, 121 and 900 are not.
Return how many stamps in that range are clean. When n is 0 the range holds the single number 0.
Examples
Example 1
- Input
- n = 1
- Output
- 10
The stamps run from 0 through 9. Each is a single digit, so none of them repeats a digit and all ten are clean.
Example 2
- Input
- n = 3
- Output
- 739
The stamps run from 0 through 999, and 739 of them use no digit twice. For instance 5, 40 and 907 count, while 11, 121 and 900 do not.
Example 3
- Input
- n = 5
- Output
- 32491
The stamps run from 0 through 99999, and 32491 of them use no digit twice. For instance 13579 counts, while 13577 does not.
Constraints
- 0 <= n <= 8
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_clean_stamps(n: int) -> int:public int countCleanStamps(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's