Skip to the code
cf.
+25 XP

#518 Count Coupon Combinations

medium

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.

Example 1

Input: coupons = [2,3,5], discount = 10
Output: 4

5 + 5, 5 + 3 + 2, 3 + 3 + 2 + 2, and 2 + 2 + 2 + 2 + 2.

Example 2

Input: coupons = [4], discount = 6
Output: 0

Multiples of 4 skip 6.

Constraints

  • 1 <= coupons.length <= 100
  • 1 <= coupons[i] <= 5000, all different
  • 0 <= discount <= 5000
Saved in this browser

Run 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).