Talentd
FleetCode

2180. Count Integers With Even Digit Sum

Easy71.1% acceptance1 company

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 = 4
Output: 2
Explanation:
The only integers less than or equal to 4 whose digit sums are even are 2 and 4.    

Example 2:

Input: num = 30
Output: 14
Explanation:
The 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 company

Hints open one at a time

Hint 1
Iterate through all integers from 1 to num.
Hint 2
For any integer, extract the individual digits to compute their sum and check if it is even.
5:30
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def countEven(self, num: int) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
4
Input
30
Your code is saved on this device.Solution