2-D Dynamic Programming Digit DP
602. Count Numbers with Unique Digits
Given an integer n, return how many whole numbers x with 0 ≤ x < 10n have no digit
that appears twice.
Numbers are written the usual way, with no leading zeros. So 7 is the one digit 7, not 007, and 0 is
the one digit 0. For example, 3051 counts, because its four digits are all different, but 2020 and 11
do not.
Example 1
Input: n = 3
739Explanation: The numbers below 1000 are counted. All 10 one-digit numbers count. Of the two-digit numbers, 81 count (all but 11, 22, …, 99), and 648 three-digit numbers count. That makes 10 + 81 + 648 = 739.
Example 2
Input: n = 0
1Explanation: The only number below 100 = 1 is 0, and its one digit does not repeat.
Example 3
Input: n = 1000000000
8877691Check your understanding
Work out the answer for this input before you write any code.
Constraints
0 ≤ n ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.