Skip to content
BASA DSA

Partition Equal Subset Sum

Medium1-D Dynamic Programming

Return whether all entries of nums can be divided into two disjoint groups with equal sums, using every entry exactly once.

Example 1

Input
nums = [1,5,11,5]
Output
true

Explanation

The single 11 balances 1+5+5.

Example 2

Input
nums = [1,2,4]
Output
false

Explanation

Total 7 is odd, so equal integer halves are impossible.

Example 3

Input
nums = [2,2,3,5]
Output
false

Explanation

Total 12 is even but no subset sums to 6.

Constraints

  • 1 <= len(nums) <= 200
  • Values are 1..100

Function contractcanPartitionArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…