Data Structures & AlgorithmsHardCAT · TCS NQT Digital
Problem: Count the integers from 1 to 999 whose decimal digit sum is divisible by 7.
- A. 140
- B. 36
- C. 139
- D. 142
Correct answer: C. 139
Digit sums divisible by 7 are 7, 14, 21 (max 27): 36 + 75 + 28 = 139 numbers in 1..999. Including 0 gives 140, counting only digit sum exactly 7 gives 36, and counting multiples of 7 instead gives 142.
More Coding Interview Problems questions
- Problem: Compute Euler's totient φ(n) summed over n = 1 to 30 (φ(n) counts integers in [1, n] coprime to n, with φ(1) = 1).
- Problem: How many positive divisors does 720 have?
- Problem: Find the modular inverse of 7 modulo 26 (the value x with 0 ≤ x < 26 such that 7x ≡ 1 mod 26).
- Problem: A Gray code of 4 bits is generated as g = n XOR (n >> 1) for n = 0 to 15. What is the Gray code value of n = 11?
- Problem: The sum of the digits of 2^100 written in base 10 is computed. What is that sum?
- Problem: In a spiral traversal of a 5×5 matrix filled row-wise with 1 to 25, the traversal starts at the top-left and goes right, then…