Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integers in the range 1 to 100 are both a multiple of 3 and have a digit sum equal to 6?
- A. 33
- B. 16
- C. 7
- D. 6
Correct answer: C. 7
Digit sum 6 already forces divisibility by 3, so the answer is just 6, 15, 24, 33, 42, 51, 60: seven numbers. 33 counts all multiples of 3, 16 counts multiples of 6, and leaving out 60 gives 6.
More Coding Interview Problems questions
- Problem: The string "abcdefg" is rotated right by 3 positions. What is the first character of the rotated string?
- Problem: For the set {1, 2, 3, 4, 5, 6, 7, 8}, how many 3-element subsets have a sum that is even?
- Problem: In a list of 6 candidates, each candidate is either rejected or accepted. The number of ways to accept at least 2 and at most 4…
- Problem: A sequence is generated from 1 by repeatedly applying: x → x + (x mod 4). Starting at x = 1, what is the value after 6 steps?
- Problem: An array of length 7 holds the values 0 to 6 in some order; the position of value k is pos[k]. For the array [2, 0, 3, 6, 1, 5…
- Problem: From the string "3a7b2c" the digits are extracted and summed. What is the sum of the digits?