Count three-digit numbers with distinct digits
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's understanding of digit manipulation, basic combinatorics, and implementation of value-range constraints in coding problems. As a Coding & Algorithms problem it is commonly asked because it reveals attention to edge cases and correctness when counting under bounds, testing practical implementation skills rather than purely theoretical reasoning.
Constraints
- 100 <= left <= right <= 999
- A straightforward scan from `left` to `right` is acceptable
Examples
Input: (120, 130)
Expected Output: 9
Explanation: Valid numbers are 120, 123, 124, 125, 126, 127, 128, 129, and 130.
Input: (100, 100)
Expected Output: 0
Explanation: 100 has digits 1, 0, 0, so the digit 0 repeats.
Input: (102, 102)
Expected Output: 1
Explanation: 102 has digits 1, 0, and 2, which are all distinct.
Input: (987, 999)
Expected Output: 1
Explanation: Only 987 has all distinct digits. Every other number in this range repeats at least one digit.
Input: (100, 999)
Expected Output: 648
Explanation: There are 9 choices for the hundreds digit (1-9), 9 choices for the tens digit (0-9 except the hundreds digit), and 8 choices for the ones digit, giving 9 * 9 * 8 = 648.
Hints
- For each number, extract its hundreds, tens, and ones digits using integer division and modulo.
- The range has at most 900 numbers, so checking each number one by one is efficient enough.