Number of Beautiful Integers in the Range

You are given positive integers low, high, and k.

A number is beautiful if it meets both of the following conditions:

  • The count of even digits in the number is equal to the count of odd digits.
  • The number is divisible by k.

Return the number of beautiful integers in the range [low, high].

Example 1
Inputlow = 10, high = 20, k = 3
Output2
There are 2 beautiful integers in the given range, 12 and 18, because each has equal counts of even and odd digits and is divisible by 3.
Example 2
Inputlow = 1, high = 10, k = 1
Output1
There is 1 beautiful integer in the given range, 10, because it has 1 odd digit and 1 even digit and is divisible by 1.

Constraints

  • 0 < low <= high <= 10^9
  • 0 < k <= 20

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate