Talentd
FleetCode

4060. Count Evenly Good Integers

Hard77.8% acceptancePremium elsewhere, free here

You are given two integers l and r.

An integer is called evenly good if it contains an even number of even digits.

Return the number of evenly good integers in the inclusive range [l, r].

Example 1:

Input: l = 18, r = 22

Output: 3

Explanation:

The evenly good integers in the range [18, 22] are:

  • 19, because it contains 0 even digits.
  • 20, because it contains 2 even digits.
  • 22, because it contains 2 even digits.

Thus, the answer is 3.

Example 2:

Input: l = 98, r = 101

Output: 2

Explanation:

The evenly good integers in the range [98, 101] are:

  • 99, because it contains 0 even digits.
  • 100, because it contains 2 even digits.

Thus, the answer is 2.

Example 3:

Input: l = 1, r = 10

Output: 5

Explanation:

The evenly good integers in the range [1, 10] are 1, 3, 5, 7, and 9, because each of them contains 0 even digits. Thus, the answer is 5.

Constraints:

  • 1 <= l <= r <= 1015
Still stuck?Read the written solution.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples

No sample inputs for this problem yet. The examples in the statement show the format.

Your code is saved on this device.Solution