1233. Count Numbers with Unique Digits

HardDynamic ProgrammingDigit DPCombinatorics

Given n and a numeric base, count the integers x with 0 <= x < base^n whose digits in that base are all distinct. (With base = 10 this is the classic count of numbers with unique digits.) The input is JSON {n, base}.

Input: JSON {n, base}.

Output: Integer — the count of numbers with all-distinct digits.

Examples

Example 1
Input: {"n":2,"base":10}
Output: 91
Explanation: All of 0-99 except the nine repeated-digit numbers.
Example 2
Input: {"n":0,"base":10}
Output: 1
Explanation: Only 0.
Example 3
Input: {"n":1,"base":10}
Output: 10
Explanation: The digits 0 through 9.

Constraints

Asked by

GoogleMicrosoftBloombergMetaAmazon
Solve this problem in the editor →