PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • Meta
  • Coding & Algorithms
  • Software Engineer

Count three-digit numbers with distinct digits

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

### Problem Given two integers `left` and `right` such that `100 ≤ left ≤ right ≤ 999`, count how many **three-digit** integers `x` in the inclusive range `[left, right]` have **all three digits distinct** (i.e., no two digits are the same). A three-digit number `x` has digits `a` (hundreds), `b` (tens), `c` (ones). It is valid if `a`, `b`, and `c` are all different: `a != b`, `a != c`, and `b != c`. ### Input - Two integers: `left`, `right`. ### Output - A single integer: the count of valid numbers in `[left, right]`. ### Constraints - `100 ≤ left ≤ right ≤ 999` - The intended solution should run in time no worse than `O(right^2)` (a straightforward scan from `left` to `right` is acceptable). ### Example - Input: `left = 120`, `right = 130` - Output: `8` - Explanation: Valid numbers are `120, 123, 124, 125, 126, 127, 128, 129` (numbers like `121` or `122` are invalid due to repeated digits).

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.

Given two integers `left` and `right` such that `100 = left = right = 999`, count how many three-digit integers `x` in the inclusive range `[left, right]` have all three digits distinct. If a number `x` has digits `a` (hundreds), `b` (tens), and `c` (ones), then it is valid when `a != b`, `a != c`, and `b != c`. For example, in the range `120` to `130`, the valid numbers are `120, 123, 124, 125, 126, 127, 128, 129, 130`, so the answer is `9`.

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

  1. For each number, extract its hundreds, tens, and ones digits using integer division and modulo.
  2. The range has at most 900 numbers, so checking each number one by one is efficient enough.
Last updated: Apr 22, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)