Trains the technique from
LeetCode 377Combination Sum IVThis 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 yard sells paving slabs in the widths listed in widths, all different, and holds an unlimited number of each. A path of length span is laid by putting slabs down one after another from the gate outwards, and it counts as finished when the widths laid add up to exactly span.
Two layouts are the same only when they lay the same widths in the same order from the gate. So on a span of 5 with widths 2 and 3 available, laying 2 then 3 is one layout and laying 3 then 2 is a second.
Return how many layouts finish the path. Return 0 if none do. The count is guaranteed to fit in a signed 32-bit integer for every input you are given.
Example 1
Two slabs of 11 finish the path, and so does a run of three 5s together with one 7, which can be laid in four orders depending on where the 7 goes.
Example 2
No run of 4s and 6s adds up to 9.
Example 3
Three 8s reach 24, and that is the only layout available.
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 slab_layouts(widths: list[int], span: int) -> int:public int slabLayouts(int[] widths, int span)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.