Count Integers With Even Digit Sum - Problem
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.
Input & Output
Example 1 — Small Number
$
Input:
num = 4
›
Output:
2
💡 Note:
Check numbers 1-4: 1(sum=1,odd), 2(sum=2,even), 3(sum=3,odd), 4(sum=4,even). Count of even sums = 2.
Example 2 — Larger Number
$
Input:
num = 30
›
Output:
14
💡 Note:
Among numbers 1-30, exactly 14 have even digit sums (like 2,4,6,8,11,13,15,17,20,22,24,26,28,29).
Example 3 — Single Digit
$
Input:
num = 9
›
Output:
4
💡 Note:
Numbers 1-9 with even digit sums: 2,4,6,8. Total count = 4.
Constraints
- 1 ≤ num ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given positive integer num = 4
2
Process
Check each number 1 to 4, calculate digit sums
3
Output
Count numbers with even digit sums
Key Takeaway
🎯 Key Insight: Count numbers where the sum of digits is divisible by 2
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code