Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: Let g(n) be the number of integers in [1, n] whose decimal digit sum is even. What is g(50)?

  1. A. 25
  2. B. 24
  3. C. 26
  4. D. 4

Correct answer: B. 24

Digit sums are even for 4 of 1..9, then 5 per decade for 10..49, and 50 has sum 5, so g(50) = 4 + 20 = 24. Counting even numbers instead gives 25, odd digit sums number 26, and 4 covers only 1..9.

More Coding Interview Problems questions

Exams that ask this topic