Partition Equal Subset Sum

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code
  • Pro

Write canPartition(nums): return true if the numbers in nums can be split into two groups with equal sums, every number going into exactly one group, and false if not. nums holds 1 to 200 whole numbers from 1 to 100. Leave nums unchanged. For example, canPartition([1, 5, 11, 5]) is true (1 + 5 + 5 and 11), and canPartition([1, 2, 3, 5]) is false. The checks include 200 numbers, so trying every subset is too slow: keep track of which sums up to half the total some of the numbers seen so far can make.

Your code must pass

  • Finds an equal split
  • Returns false when no split works
  • Handles one or two numbers
  • Is fast enough for 200 numbers