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)?
- A. 25
- B. 24
- C. 26
- 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
- Problem: The Euler's totient of 36 is φ(36), the count of integers in [1, 36] coprime to 36. What is φ(36)?
- Problem: A pair of ropes is connected as a chain: lengths 3, 4, 5 are joined in the order listed, each join costs the sum of the two…
- Problem: From the list [5, 3, 3, 7, 12, 9], what is the second-smallest distinct value (duplicates count once)?
- Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?
- Problem: The mapping of letters is A=1 through Z=26. What is the sum of the values of the letters in the word "MATH"?
- Problem: The number of ways to choose 4 people from 9 so that a specific two people are never both chosen is what value?