Asked at

Partition Equal Subset Sum

Medium
Verified
ArrayDynamic ProgrammingKnapsack~25 min

Given an array nums of positive integers, decide whether it can be split into two subsets with equal sums.

The input arrives as a single array nums. Return true or false.

Examples

in[1, 5, 11, 5]
outtrue

[1, 5, 5] and [11] both sum to 11.

in[1, 2, 3, 5]
outfalse

Total is 11, odd, so no equal split exists.

Constraints

  • 1 ≤ nums.length ≤ 200
  • 1 ≤ nums[i] ≤ 100
  • Target: O(n · sum) time

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.