Partition Equal Subset Sum

Given an array of positive integers, determine whether it can be partitioned into two subsets with equal sum. This is the canonical partition problem and a direct subset-sum reduction.

Input Format

nums = array of positive integers

Output Format

true if nums can be partitioned into two equal-sum subsets

Constraints

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

Examples

Example 1:

Input:

nums = [1,5,11,5]

Output:

true

Explanation:

The array can be split into [1,5,5] and [11].

Example 2:

Input:

nums = [1,2,3,5]

Output:

false

Explanation:

The sum is odd, so equal partition is impossible.

Loading...
Partition Equal Subset Sum - Dp Knapsack