Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many numbers from 1 to 1000 have a digit sum divisible by 9?
- A. 55
- B. 112
- C. 111
- D. 333
Correct answer: C. 111
Digit sum ≡ x (mod 9), so this counts multiples of 9 in 1..1000: 111. Requiring digit sum exactly 9 gives 55, adding 0 gives 112, and 333 counts digit sums divisible by 3.
More Coding Interview Problems questions
- Problem: How many ways are there to write 20 as an ordered sum of parts from {2, 3, 5}?
- Problem: The sequence a0 = 0 and a(n) = a(n−1) + (n mod 3) for n ≥ 1 is defined. What is a(30)?
- Problem: A square matrix 4×4 has entry (i, j) equal to (i + 2j) mod 5. What is the sum of the entries on the main diagonal?
- Problem: The sum of the squares of the first 15 natural numbers, reduced modulo 7, is what value?
- Problem: Consider the array [3, 7, 4, 9, 2, 8, 5]. Two selection rounds are performed: first pick the largest value and remove it, then…
- Problem: Dictionary: a list of words is ["cat", "dog", "bat", "dig"]. Words are grouped by changing exactly one letter (Hamming distance…