Trains the technique from
LeetCode 518Coin Change IIThis 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 bindery keeps ribbon wound on spools of a few fixed lengths, given in spools. The lengths listed are all different from one another, and the storeroom carries an unlimited number of spools at each of those lengths.
An order calls for exactly target centimetres of ribbon, put together by joining whole spools end to end. A spool is never cut. Count how many different assemblies hit the order exactly.
Two assemblies count as the same whenever they draw the same number of spools at every length, so the sequence in which the spools get joined is irrelevant.
A target of 0 is a legal order, and the assembly that joins nothing at all fills it, so the answer in that case is 1. When no assembly reaches target, answer 0. The count is guaranteed to fit in a signed 32-bit integer.
Example 1
The four assemblies are one 4 beside two 1s, two 3s, one 3 beside three 1s, and six 1s.
Example 2
Joining spools of length 5 can only ever reach a multiple of 5, and 7 is not one.
Example 3
Nothing has to be joined to fill an order of zero centimetres, and that empty assembly is the single way to do it.
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 spool_assemblies(target: int, spools: list[int]) -> int:public int spoolAssemblies(int target, int[] spools)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.