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 (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.
left
,
right
.
[left, right]
.
100 ≤ left ≤ right ≤ 999
O(right^2)
(a straightforward scan from
left
to
right
is acceptable).
left = 120
,
right = 130
8
120, 123, 124, 125, 126, 127, 128, 129
(numbers like
121
or
122
are invalid due to repeated digits).