Quick Overview

A coding question that asks you to count the three-digit integers in an inclusive range whose hundreds, tens and units digits are all different from one another. It tests digit extraction, inclusive range boundaries and treating zero digits like any other digit.

Count Three-Digit Numbers With All-Distinct Digits in a Range

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

Given two three-digit integers `left` and `right`, count how many integers in the inclusive range from `left` to `right` have three pairwise different digits, that is, no digit appears more than once in the number. ### Function Signature ```python def count_distinct_digit_numbers(left: int, right: int) -> int: ``` ### Rules - Both `left` and `right` belong to the range. - A number qualifies only when its hundreds, tens and units digits are three different digits. A zero digit is treated like any other digit: `890` qualifies, while `900` and `808` do not. - Return the count as a single integer, or `0` when no number in the range qualifies. ### Constraints - `100 <= left <= right <= 999` ### Examples **Example 1** ```text Input: left = 876, right = 890 Output: 3 ``` Only `876`, `879` and `890` qualify. `877` and `878` repeat a digit, and every number from `880` to `889` repeats the digit 8. **Example 2** ```text Input: left = 100, right = 110 Output: 8 ``` `102` through `109` qualify; `100`, `101` and `110` each repeat a digit. **Example 3** ```text Input: left = 987, right = 999 Output: 1 ``` Only `987` qualifies.

Overview: A coding question that asks you to count the three-digit integers in an inclusive range whose hundreds, tens and units digits are all different from one another. It tests digit extraction, inclusive range boundaries and treating zero digits like any other digit.

Read the full Capital One Software Engineer interview experience this question came from

Given two three-digit integers `left` and `right`, return how many integers `n` with `left <= n <= right` have three pairwise different digits: the hundreds, tens and units digits of `n` must all differ from one another, so no digit appears more than once in the number. Rules: - The range is inclusive: both `left` and `right` belong to the range and are counted when they qualify. - A zero digit is treated like any other digit. For example, `890` qualifies, while `900` and `808` do not. - Return the count as a single integer, or `0` when no number in the range qualifies. Constraints: - `100 <= left <= right <= 999` No value can exceed 2^31-1: the arguments are at most 999 and the answer is at most 648, so 32-bit `int` is sufficient in every language. Example 1: Input: left = 876, right = 890 Output: 3 Explanation: Only 876, 879 and 890 qualify. 877 and 878 repeat a digit, and every number from 880 to 889 repeats the digit 8. Example 2: Input: left = 100, right = 110 Output: 8 Explanation: 102 through 109 qualify; 100, 101 and 110 each repeat a digit.

Constraints

  • 100 <= left <= right <= 999
  • left and right are integers and the range is inclusive of both endpoints
  • The answer is an integer from 0 through 648

Examples

Input: (987, 987)

Expected Output: 1

Explanation: Singleton range on a qualifying number: 9, 8 and 7 are distinct.

Input: (999, 999)

Expected Output: 0

Explanation: Singleton range at the upper bound on a non-qualifying number.

Hints

  1. Every number in the range has exactly three digits, so there is no leading-zero case to handle.
  2. A number qualifies only when all three pairs of digits differ, including the hundreds and units digits, not just neighbouring ones: 808 must be rejected.
  3. Both endpoints belong to the range, and a zero digit is compared like any other digit: 890 counts, 900 does not.

Loading coding console...