Number of Beautiful Integers in the Range - Problem
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].
Input & Output
Example 1 — Basic Range
$
Input:
low = 10, high = 20, k = 6
›
Output:
2
💡 Note:
Numbers 12 (even=1, odd=1, 12%6=0) and 18 (even=1, odd=1, 18%6=0) are beautiful
Example 2 — Larger k
$
Input:
low = 1, high = 10, k = 1
›
Output:
1
💡 Note:
Only number with equal even/odd digits in range [1,10] is none for single digits, but all are divisible by 1
Example 3 — No Valid Numbers
$
Input:
low = 5, high = 5, k = 1
›
Output:
0
💡 Note:
Single digit 5 has 0 even and 1 odd digit, so counts are not equal
Constraints
- 1 ≤ low ≤ high ≤ 109
- 1 ≤ k ≤ 20
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code