Trains the technique from
LeetCode 1498Number of Subsequences That Satisfy the Given Sum ConditionThis 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 bin holds parts whose sizes read sizes. A pick is any non-empty choice of parts taken by position, so two picks differ when the positions differ, even where the sizes match.
A pick is safe when its smallest size added to its largest size comes to at most cap. A pick of one part is safe when twice that size is at most the cap.
Return how many safe picks there are, given as the remainder after dividing by 1000000007.
Example 1
Sorted, the sizes read 3, 5, 6, 7. The safe picks are 3 alone, 3 with 5, 3 with 6, and 3 with 5 and 6. Anything holding the 7 needs its smallest at 2 or less, and anything without the 3 has its smallest at 5, which pairs with nothing here.
Example 2
The only pick is the single part, whose smallest and largest are both 1, adding to two, which is over the cap.
Example 3
Either part alone comes to ten, exactly the cap, and so does the pick holding both, so all three picks are safe.
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 num_subseq(sizes: list[int], cap: int) -> int:public int numSubseq(int[] sizes, int cap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.