InferenceAI

Enter at least two characters to search.

Start free

Equal Sum Split

mediumDynamic Programming25 min25 XP

Return True if nums (positive integers) can be split into two groups with equal sums.

Requirements

  • Subset-sum DP over sums up to total/2\text{total} / 2. A Python integer used as a bitset makes this very fast.

Examples

EXAMPLE WALKTHROUGHpossible

A guided view of the published example, not a trace of your code.

INPUT[[1,5,11,5]]
TASKequal_sum_split()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: nums = [1,5,11,5]

Output: true

Explanation: possible

Input: nums = [1,2,3,5]

Output: false

Explanation: impossible

Input: nums = [2,2]

Output: true

Explanation: two equal

Hint 1

If the total is odd, the answer is False.

Hint 2

Track every reachable subset sum.

Topics

DSADynamic ProgrammingPython