Talentd
FleetCode

3032. Count Numbers With Unique Digits II

Easy87.4% acceptance1 companyPremium elsewhere, free here
Given two positive integers a and b, return the count of numbers having unique digits in the range [a, b] (inclusive).

Example 1:

Input: a = 1, b = 20
Output: 19
Explanation: All the numbers in the range [1, 20] have unique digits except 11. Hence, the answer is 19.

Example 2:

Input: a = 9, b = 19
Output: 10
Explanation: All the numbers in the range [9, 19] have unique digits except 11. Hence, the answer is 10. 

Example 3:

Input: a = 80, b = 120
Output: 27
Explanation: There are 41 numbers in the range [80, 120], 27 of which have unique digits.

Constraints:

  • 1 <= a <= b <= 1000

Asked at 1 company

Hints open one at a time

Hint 1
You can traverse over all numbers and check if the current number has unique digits or not.
4:54
Still stuck?Read 2 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
1
20
Input
9
19
Input
80
120
Your code is saved on this device.Solution