All problems
0708MediumMathDynamic ProgrammingBacktracking

Clean Crate Stamps

Tracked in this browser only
Write code

Trains the technique from

LeetCode 357Count Numbers with Unique Digits

This 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.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_clean_stamps(n: int) -> int:
Java
public int countCleanStamps(int n)
September 7
Apply