Problem · Array

Count Numbers with Unique Digits

Learn this problem
EasySalesforceOA
See Salesforce hiring insights

Problem statement

Given a list of numbers, count the number of numbers in the range [l,r] such that the number does not contain duplicate digits.

Function

countUniqueDigits(numbers: int[], l: int, r: int) → int

Examples

Example 1

numbers = [1, 2, 11, 55, 989, 51, 60, 7007]l = 1r = 5return = 2
In the given range [1,5], the numbers 1 and 2 do not contain any duplicate digits, so the answer is 2. (Explanation may not be 100% correct. For reference only. If you find anything wrong, pls feel free to lmk! Many thanks in advance!)

Example 2

numbers = [1, 2, 11, 55, 989, 51, 60, 7007]l = 0r = 7return = 4
In the given range [0,7], the numbers 1, 2, 5 (from 51), and 6 (from 60) do not contain any duplicate digits, so the answer is 4. (Explanation may not be 100% correct. For reference only. If you find anything wrong, pls feel free to lmk! Many thanks in advance!)

Example 3

numbers = [1, 2, 11, 55, 989, 51, 60, 7007]l = 5r = 7return = 2
In the given range [5,7], the numbers 5 (from 51) and 6 (from 60) do not contain any duplicate digits, so the answer is 2. (Explanation may not be 100% correct. For reference only. If you find anything wrong, pls feel free to lmk! Many thanks in advance!)

More Salesforce problems

drafts saved locally
public int countUniqueDigits(int[] numbers, int l, int r) {
  // write your code here
}
numbers[1, 2, 11, 55, 989, 51, 60, 7007]
l1
r5
expected2
checking account