1237. Count Special Integers

HardDynamic ProgrammingDigit DP

An integer is special if all of its decimal digits are distinct. Given n, count the special integers in the range [1, n]. The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the count of special integers.

Examples

Example 1
Input: {"n":20}
Output: 19
Explanation: All of 1-20 except 11.
Example 2
Input: {"n":5}
Output: 5
Explanation: All single digits up to 5.
Example 3
Input: {"n":135}
Output: 110
Explanation: 110 special integers up to 135.

Constraints

Asked by

Google
Solve this problem in the editor →