You are given three integers l, r, and k.
Consider all possible integers consisting of exactly k digits, where each digit is chosen independently from the integer range [l, r] (inclusive). If 0 is included in the range, leading zeros are allowed.
Return an integer representing the sum of all such numbers. Since the answer may be very large, return it modulo 109 + 7.
Example 1:
Input: l = 1, r = 2, k = 2
Output: 66
Explanation:
k = 2 digits in the range [1, 2] are 11, 12, 21, 22.11 + 12 + 21 + 22 = 66.Example 2:
Input: l = 0, r = 1, k = 3
Output: 444
Explanation:
k = 3 digits in the range [0, 1] are 000, 001, 010, 011, 100, 101, 110, 111.0, 1, 10, 11, 100, 101, 110, 111.Example 3:
Input: l = 5, r = 5, k = 10
Output: 555555520
Explanation:
k = 10 digits in the range [5, 5].5555555555 % (109 + 7) = 555555520.
Constraints:
0 <= l <= r <= 91 <= k <= 109Solutions for this problem are being prepared.
Try solving it yourselfPractice Sum of K-Digit Numbers in a Range with our built-in code editor and test cases.
Practice on FleetCodePractice this problem
Open in Editor