A promotions page wants to show how many ways a shopper can reach a discount by stacking coupons. Each coupon type in coupons has a different dollar value, and any number of each type may be used.
Write countCombos(coupons, discount) that returns how many different combinations of coupons add up to exactly discount. The order of coupons does not matter: 2 + 3 and 3 + 2 are the same combination. A discount of 0 has one combination: no coupons. Return the count modulo 1000000007.
Input: coupons = [2,3,5], discount = 10 Output: 4
5 + 5, 5 + 3 + 2, 3 + 3 + 2 + 2, and 2 + 2 + 2 + 2 + 2.
Input: coupons = [4], discount = 6 Output: 0
Multiples of 4 skip 6.
1 <= coupons.length <= 1001 <= coupons[i] <= 5000, all different0 <= discount <= 5000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #518 Count Coupon Combinations. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.