Data Structures & AlgorithmsModerateTCS NQT Digital · Number puzzle
Problem: How many integers x with 1 <= x <= 100 have no two adjacent equal decimal digits? Use the rule that a one-digit number always qualifies.
Problem: How many integers x with 1 <= x <= 100 have no two adjacent equal decimal digits? Use the rule that a one-digit number always qualifies.
cnt = 0
for x in range(1, 101):
s = str(x)
if all(s[i] != s[i + 1] for i in range(len(s) - 1)):
cnt += 1
print(cnt)What is printed?- A. 81
- B. 90
- C. 99
- D. 100
Correct answer: B. 90
All 9 one-digit numbers qualify, and 81 two-digit numbers have distinct digits (excluding 11, 22, ..., 99). The number 100 contains '00' and is excluded, so the total is 90.
More Coding Interview Problems questions
- Problem: What is the sum of all divisors of 360 = 2^3 3^2 5?
- Problem: Find the smallest positive x satisfying x ≡ 2 (mod 3), x ≡ 3 (mod 5) and x ≡ 2 (mod 7).
- Problem: Which pair (x, y) satisfies 240x + 46y = gcd(240, 46)?
- Problem: Cows must be placed in stalls at positions [1, 2, 4, 8, 9] so that the minimum distance between any two cows is as large as…
- Problem: Trains arrive at times [900, 940, 950, 1100, 1500, 1800] and depart at [910, 1200, 1120, 1130, 1900, 2000]. The two-pointer code…
- Problem: Return, for each index i, the product of all other elements (no division allowed). Print the list for a = [2, 3, 4, 5]. python a…