Standard Bar Recursion · Subsequences Pattern O(2^n) branch walks in the worst case · O(target) recursion depth beyond the output
A finance clerk bundles expense line items toward an exact grant total, but each line item on the sheet may be used at most once — even when two items carry the same amount, they are separate lines. After sorting the sheet, the clerk builds bundles by taking an item and moving on, or skipping ahead; when several identical amounts sit side by side, only the first may open a branch at that depth, so no bundle is ever filed twice.
Input: An array candidates of positive integers (duplicates allowed) and an integer target.
Output: Every unique combination summing to target, sorted lexicographically by the verifier.
1 <= candidates.length <= 1001 <= candidates[i] <= 501 <= target <= 30Input: {"candidates":[10,1,2,7,6,1,5],"target":8}
Output: [[1,1,6],[1,2,5],[1,7],[2,6]]
Four unique bundles; the two 1s are distinct items, which is why [1, 1, 6] exists but no bundle appears twice.
Input: {"candidates":[2,5,2,1,2],"target":5}
Output: [[1,2,2],[5]]
The 5 alone works, and one pair of 2s joins the single 1; duplicate 2-branches collapse.