Data Structures & AlgorithmsModerateTCS NQT Digital · CAT
Problem: How many two-digit numbers (10–99) have digits that sum to exactly 9?
- A. 10
- B. 9
- C. 90
- D. 8
Correct answer: B. 9
Two-digit numbers with digit sum 9: 18, 27, 36, 45, 54, 63, 72, 81, 90 = 9. Counting two-digit multiples of 9 adds 99 (digit sum 18) for 10, 90 counts all two-digit numbers, and forgetting 90 gives 8.
More Coding Interview Problems questions
- Problem: The undirected graph on vertices 0, 1, 2 has edges 0-1 (5), 1-2 (5) and 0-2 (12). What is the shortest path length from 0 to 2?
- Problem: A complete binary tree has all levels full with depths 0 to 4 (root at depth 0). How many nodes does it have in total?
- Compute the sum of gcd(i, j) over all pairs 1 ≤ i < j ≤ 50. python from math import gcd print(sum(gcd(i,j) for i in range(1,51) for j in…
- How many integers n with 1 ≤ n ≤ 10000 have exactly four positive divisors? Count them with a divisor-count sieve. python N=10000…
- Array a = [3, 8, 2, 9, 5, 7, 6]. Count the index triples i < j < k such that the three values, sorted, are equally spaced (an arithmetic…
- Count the binary strings of length 10 that contain no two adjacent 1s and also contain a run of at least three consecutive 0s. Brute-force…