Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Can we pick a subset summing to half of total?

Approach

If total sum is odd, impossible. Otherwise target = sum/2. Do 0/1 knapsack boolean DP: dp[t] = reachable sum t. Iterate nums and update t downward to avoid reuse.

Why it works

A partition into equal sums exists iff some subset sums to target.

Code
Loading...
Complexity
Time: O(n * target)
Space: O(target)
Solution
Updated: 2026-02-23

Idea

Can we pick a subset summing to half of total?

Approach

If total sum is odd, impossible. Otherwise target = sum/2. Do 0/1 knapsack boolean DP: dp[t] = reachable sum t. Iterate nums and update t downward to avoid reuse.

Why it works

A partition into equal sums exists iff some subset sums to target.

Code
Loading...
Complexity
Time: O(n * target)
Space: O(target)