Partition Equal Subset Sum - Problem

Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal, or false otherwise.

Key Points:

  • Each element can only be used once
  • Both subsets must contain at least one element
  • The order of elements within subsets doesn't matter

Input & Output

Example 1 — Basic Partition
$ Input: nums = [1,5,11,5]
Output: true
💡 Note: Array can be partitioned as [1,5,5] and [11]. Both subsets have sum = 11.
Example 2 — Cannot Partition
$ Input: nums = [1,2,3,5]
Output: false
💡 Note: Total sum = 11 (odd), so cannot be split into two equal subsets.
Example 3 — Minimum Case
$ Input: nums = [1,1]
Output: true
💡 Note: Can partition as [1] and [1]. Both subsets have sum = 1.

Constraints

  • 1 ≤ nums.length ≤ 200
  • 1 ≤ nums[i] ≤ 100

Visualization

Tap to expand
Partition Equal Subset Sum: [1,5,11,5]Goal: Split into two subsets with equal sums15115Subset 1[1, 5, 5]Subset 2[11]Sum = 11Sum = 11Result: true (Equal partition found)
Understanding the Visualization
1
Input
Array of integers to partition
2
Process
Find if we can split into two equal-sum subsets
3
Output
Return true if partition possible, false otherwise
Key Takeaway
🎯 Key Insight: We only need to check if one subset with sum = total/2 exists
Asked in
Amazon 45 Google 38 Facebook 32 Microsoft 28
185.0K Views
High Frequency
~25 min Avg. Time
8.5K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen