Trains the technique from
LeetCode 39Combination SumThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A mailroom keeps rolls of stamps. denominations lists the face values in stock, all different, and the roll for each value is effectively endless, so a value may be used as many times as you like.
A parcel needs exactly postage in stamps: no less, and no overpaying. A mix is a multiset of face values whose sum is exactly postage.
Return every distinct mix the stock allows. Two mixes are the same if one uses each face value the same number of times as the other, so [4, 4, 5] and [4, 5, 4] count as one mix. Ordering is free: the values inside a mix may be listed in any order, and the mixes themselves may come in any order. If the parcel cannot be franked exactly, return an empty list.
Example 1
Two 4s and a 5 reach 13, and so does a 4 beside a 9. Nothing else sums to exactly 13.
Example 2
Only one face value is stocked, and three of them land on 18, which is allowed because the roll never runs out.
Example 3
Every stocked value already exceeds 5, so the parcel cannot be franked exactly and nothing is reported.
The groups you return, and the values inside each group, may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def postage_mixes(denominations: list[int], postage: int) -> list[list[int]]:public List<List<Integer>> postageMixes(int[] denominations, int postage)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.