Overview
Subsequences (unlike substrings) don't have to be contiguous. The most common pattern is generating subsets to hit a specific sum or property.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Subsequence problems involve iterating through an array and making a "Pick" or "Skip" decision for each element.
Subsequences (unlike substrings) don't have to be contiguous. The most common pattern is generating subsets to hit a specific sum or property.
For every element at index `i`, we branch into two recursive paths: one where we include `nums[i]` in our subsequence, and one where we don't.
Because there are 2^N total subsequences, brute force is too slow. But the number of distinct `(index, currentSum)` states is often small, allowing DP.
The 0/1 Knapsack problem is the classic example of DP on subsequences. Each item is picked or skipped to maximize value within a weight limit.