Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    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 <code>10<sup>9</sup> + 7</code>.

    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:

    • <code>1 <= num1 <= num2 <= 10<sup>22</sup></code>

    • 1 &lt;= min_sum &lt;= max_sum &lt;= 400

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer count(String num1, String num2, Integer minSum, Integer maxSum)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait