0Pricing
Competitive Programming Academy · Lesson

Subset Sum & Partition

Reach a target with a chosen subset.

The Subset Sum Question

Given numbers and a target, can any subset add up to exactly that target? It is knapsack where value equals weight.

Boolean DP, Not Value

Here you track reachability, not a maximum. Let dp[s] be True when some subset sums to exactly s.

dp = [False] * (target + 1)
dp[0] = True

All lessons in this course

  1. 0/1 Knapsack: Take or Leave
  2. Space-Optimized Knapsack
  3. Unbounded & Coin-Change DP
  4. Subset Sum & Partition
← Back to Competitive Programming Academy