Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- A. 41583
- B. 16333
- C. 8415
- D. 33168
Correct answer: D. 33168
Sum of multiples of 3 up to 500 (41583) minus multiples of 15 (8415) = 33168. 41583 skips the exclusion, subtracting multiples of 5 instead gives 16333, and 8415 is the excluded part.
More Coding Interview Problems questions
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are…
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is reduced by repeatedly removing the first two elements and appending their sum to the…