#3855
Sum of K-Digit Numbers in a Range
hard · 49.9% accepted · 37 likes · top 37%
Description
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.
Solution