101 Logo
onenoughtone

Problem Statement

Partition Equal Subset Sum

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.

Examples

Example 1:

Input: nums = [1, 5, 11, 5]
Output: true
Explanation: The array can be partitioned as [1, 5, 5] and [11].

Example 2:

Input: nums = [1, 2, 3, 5]
Output: false
Explanation: The array cannot be partitioned into equal sum subsets.

Constraints

  • 1 <= nums.length <= 200
  • 1 <= nums[i] <= 100

Problem Breakdown

To solve this problem, we need to:

  1. This problem is equivalent to finding if there exists a subset of the array with a sum equal to half of the total sum.
  2. If the total sum is odd, it's impossible to partition the array into two equal subsets.
  3. This is a variation of the 0/1 Knapsack problem, which can be solved using dynamic programming.
  4. We can use a 1D or 2D DP array to keep track of which sums are possible to achieve with the given numbers.
ProblemSolutionCode
101 Logo
onenoughtone