Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many integers in [1, 1000] have exactly three distinct decimal digits? Run the code.
Problem: How many integers in [1, 1000] have exactly three distinct decimal digits? Run the code.
print(sum(1 for x in range(1, 1001) if len(set(str(x))) == 3))What is printed?
- A. 720
- B. 900
- C. 504
- D. 648
Correct answer: D. 648
Only 3-digit numbers qualify: 9 · 9 · 8 = 648 (first digit non-zero). 10 · 9 · 8 = 720 allows a leading zero, 900 counts all 3-digit numbers, and 9 · 8 · 7 = 504 wrongly bans 0 everywhere.
More Coding Interview Problems questions
- Problem: How many primes p <= 200 have p + 6 also prime? Run the code. python def isp(n): return n > 1 and all(n % d for d in range(2…
- Problem: How many integers in [1, 2000] have an odd number of positive divisors? Run the code. python print(sum(1 for x in range(1, 2001)…
- Problem: How many 3-element subsets of {1, ..., 10} have sum 15? Run the code. python from itertools import combinations print(sum(1 for c…
- Problem: What is the largest k such that 2^k divides 12!? Run the code. python n = 12 c = 0 p = 2 while p <= n: c += n // p p = 2 print(c)…
- Problem: What is the length of the longest common prefix of 'interview', 'internet' and 'interval'? Run the code. python import os…
- Problem: How many subsets of {1, ..., 7} contain no two numbers that differ by exactly 1? Run the code. python print(sum(1 for m in…