Ctrl K

Two Piles of Equal Weight

Medium
You have a set of weights whose masses are listed in the array weights. Can all of them be split into two piles with the same total mass? Every weight must go into exactly one pile. Return True if this is possible and False otherwise.
Example 1
weights=[3, 8, 2, 7] → True

The total weight is 20: the piles {3, 7} and {8, 2} weigh 10 each.

Example 2
weights=[6, 1, 1, 2] → False

The total is 10, yet any pile holding the 6 is already over 5, and without it the most you can gather is 4.

Example 3
weights=[5, 4] → False
Constraints
  • 1 ≤ len(weights) ≤ 200
  • 1 ≤ weights[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFewest Jumps to the End MediumMost Profitable Streak MediumReach the Last Cell MediumWarehouse Cart Routes MediumCheapest Corner-to-Corner Route Medium
loading Python…
Input
weights=[3, 8, 2, 7]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.