Description
Solutions
Distinct Digit Numbers
🤘 INTERN

Given a range of integers, determine how many numbers have no repeating digits.

Example:

n = 80, m = 120

The lower and upper bounds are inclusive, so there are 120 - 79 = 41 values in the range :) Numbers without repeating characters are normal weight and others are bold. The two columns to the ight are the valid number counts per row (normal weight :) and invalid number counts (bold :)

Ther are 27 numbers with no repeating digits, and 14 other numbers in the range. Print 27.

Function Description

Complete the function countNumbers in the editor below.

countNumbers has the following parameter(s):

  1. int arr[q][2]: integer pairs representing inclusive lower (n) and upper (m) range limits

Print

For each pair arr[i], print the number of integers in the inclusive range that qualify. There is no value to return from the function.

Tomtom's note: This question is a bit special. The original question doesn't require a return type, but I’ve made the return type int[]. If the return type were void, you wouldn’t be able to practice it here.

ᡣ • . • 𐭩 ♡Credit to chizzy_elect˙ᵕ˙❀༉

Example 1:

Input:  arr = [[1, 20], [9, 19]]
Output: [19, 10]
Explanation:

Row 0 [1, 20] The set of qualifying numbers in the inclusive range between n[0] = 1 and m[0] = 20 is {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20}. This gives us c[0] = 19.

Row 1 [9, 19] The set of qualifying numbers in the inclusive range between n[1] = 9 and m[1] = 19 is {9, 10, 12, 13, 14, 15, 16, 17, 18, 19}. This gives us c[1] = 10.

Example 2:

Input:  arr = [[7, 8], [52, 80], [9, 84], [57, 64], [74, 78]]
Output: [2, 26, 47, 8, 4]
Explanation:

Row 0 [7, 8] The set of qualifying numbers in the inclusive range between n[0] = 7 and m[0] = 8 is {7, 8}. This gives us c[0] = 2.

Row 1 [52, 80] The set of qualifying numbers in the inclusive range between n[1] = 52 and m[1] = 80 is {52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80}. This gives us c[1] = 26.

Row 2 [9, 84] The set of qualifying numbers in the inclusive range between n[2] = 9 and m[2] = 84 is {9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83}. This gives us c[2] = 47.

Row 3 [57, 64] The set of qualifying numbers in the inclusive range between n[3] = 57 and m[3] = 64 is {57, 58, 59, 60, 61, 62, 63, 64}. This gives us c[3] = 8.

Row 4 [74, 78] The set of qualifying numbers in the inclusive range between n[3] = 74 and m[3] = 78 is {74, 75, 76, 78}. This gives us c[4] = 4.

Constraints:
  • 1 ≤ q ≤ 10^5
  • 1 ≤ n ≤ m ≤ 10^6
Thumbnail 0
Testcase

Result
Case 1

input:

output: