Digit Sum
Learn this problemProblem statement
There is a lottery with c coupons and p participants. Each participant picks exactly one coupon. Coupons are numbered from lowLimit to highLimit, inclusive. The winner of the lottery is any participant who owns a coupon with the sum of digits s written on it. If there is more than one winner, then the prize is split equally among them.
- Determine s in such a way that there is at least one winner, and the prize is split among the most participants.
- Also determine how many ways the required sum s can be chosen, so that the lottery is split among the maximum number of participants.
Function
waysToChooseSum(lowLimit: long, highLimit: long) → long[]
Complete the function waysToChooseSum in the editor below. The function must return an array of long integers with 2 elements:
- The total number of ways to choose sum so that maximum possible participants win the lottery.
- The number of participants who will win the lottery.
waysToChooseSum has the following parameter(s):
long lowLimit: a long integer, the starting number of the lottery couponslong highLimit: a long integer, the ending number of the lottery coupons
Examples
Example 1
lowLimit = 1highLimit = 5return = [5, 1]The sums of digits for all the tickets are different, i.e. [1,2,3,4,5]. There are 5 ways to choose the sum with 1 winner each.
Example 2
lowLimit = 3highLimit = 12return = [1, 2]The sums of digits of the 10 numbers are [3, 4, 5, 6, 7, 8, 9, 1, 2, 3]. The sum 3 is seen two times. There is 1 way to choose the maximum of 2 winners.
Constraints
lowLimit < highLimit ≤ 10^18