Dynamic programmingAnimated
Partition Equal Subset Sum
Split into two equal-sum halves: subset sum with target sum/2.
Time
O(n · sum)
Extra space
O(sum)
Use it for
Fair splitting.
How it works
- Can the numbers be split into two groups with the same sum?
- If the total is odd, impossible. Otherwise we need a subset adding to total / 2 (the rest then adds to the same).
- That is the subset-sum problem with target = total / 2.
- Update a reachable-sums row once per number. O(n × total).
Watch it run
Loading animation…