g2701_2800.s2719_count_of_integers.readme.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
2719\. Count of Integers
Hard
You are given two numeric strings `num1` and `num2` and two integers `max_sum` and `min_sum`. We denote an integer `x` to be _good_ if:
* `num1 <= x <= num2`
* `min_sum <= digit_sum(x) <= max_sum`.
Return _the number of good integers_. Since the answer may be large, return it modulo 109 + 7
.
Note that `digit_sum(x)` denotes the sum of the digits of `x`.
**Example 1:**
**Input:** num1 = "1", num2 = "12", `min_sum` = 1, max\_sum = 8
**Output:** 11
**Explanation:** There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.
**Example 2:**
**Input:** num1 = "1", num2 = "5", `min_sum` = 1, max\_sum = 5
**Output:** 5
**Explanation:** The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.
**Constraints:**
* 1 <= num1 <= num2 <= 1022
* `1 <= min_sum <= max_sum <= 400`