Count Integers With Even Digit Sum
Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.
The digit sum of a positive integer is the sum of all its digits.
Example 1
Input
num = 4Output
2The only integers less than or equal to 4 whose digit sums are even are 2 and 4.
Example 2
Input
num = 30Output
14The 14 integers less than or equal to 30 whose digit sums are even are 2, 4, 6, 8, 11, 13, 15, 17, 19, 20, 22, 24, 26, and 28.
Constraints
- 1 <= num <= 1000
Asked at 1 companies
Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.