Equal Sum Array Partition
Also known as: Partition Equal Subset Sum
Check if array can be partitioned into two equal sum subsets Example: [1,5,11,5] => true (can split into [1,5,5] and [11])
Halve the total, then it is a subset-sum question. I track which sums are reachable in one boolean row and check the target.
Examples
You write
can_partition(nums: List[int])
Example 1
- Input
- nums = [1,5,11,5]
- returns
- true
Example 2
- Input
- nums = [1,2,3,5]
- returns
- false
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsDynamic Programming
I reach for it when
- Brute force repeats the same subproblem.
- You are asked for a count, a minimum or a maximum.
Say this before you type. Say the state in one sentence, then say which smaller states it reads from.
All 37 Dynamic Programming problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.