Practice · Dynamic programming (1D) · 8 of 8

Split into Two Equal Totals

You are given a list of positive integers nums. Return true if you can put every number into one of two groups so that the two groups have the same total, and false otherwise.

Example 1

Input
nums = [2, 7, 4, 3, 6]
Output
true
[7, 4] and [2, 3, 6] both add up to 11.

Example 2

Input
nums = [1, 2, 5]
Output
false
The total is 8, but no group adds up to 4.

Example 3

Input
nums = [3, 3, 3]
Output
false
An odd total can't be split into two equal halves.

Constraints

  • nums holds 1 to 200 numbers.
  • 1 ≤ nums[i] ≤ 100