A checkout page accepts store coupons. values lists the distinct coupon values, and a customer may use each value any number of times.
Write couponMixes(values, target) that returns every distinct mix of coupons that adds up to exactly target. Write each mix as an array sorted ascending. The mixes may be listed in any order.
Two mixes are the same if they use the same values the same number of times. Return [] if no mix works.
Input: values = [2,3,5], target = 8 Output: [[2,2,2,2],[2,3,3],[3,5]]
Each mix adds to 8. [3, 5] and [5, 3] are the same mix, so it appears once.
Input: values = [4], target = 2 Output: []
The only coupon is worth more than the target.
1 <= values.length <= 101 <= values[i] <= 40, all distinct1 <= target <= 40Run 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 #303 Reusable Coupon Totals. 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.