Given an integer , you need to count all numbers such that and has all unique digits. For example, if , you are looking at numbers from 0 to 99. Numbers like 11, 22, and 33 are excluded because they have repeated digits.
Google and Bloomberg ask this to test basic combinatorial counting and the ability to handle edge cases. It requires you to understand how to build a number digit by digit and how the number of available choices decreases as you use more digits. It’s also an excellent introductory problem for "Digit DP" or backtracking.
The primary pattern is Combinatorics / Permutations.
Let .
A common error is including numbers with leading zeros as unique (e.g., counting "012" as a unique 3-digit number). In this problem, "012" is just the number 12, which is already counted in the 2-digit category. Another mistake is not stopping at , as any number with more than 10 digits must have at least one repeated digit.
For counting problems based on digits, first try a simple combinatorial approach. If the conditions are more complex (e.g., "count unique digits between and "), move to the "Digit DP" template.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Punishment Number of an Integer | Medium | Solve | |
| 4 Keys Keyboard | Medium | Solve | |
| 2 Keys Keyboard | Medium | Solve | |
| Integer Break | Medium | Solve | |
| Egg Drop With 2 Eggs and N Floors | Medium | Solve |