Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =
target =

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

Convert +/- assignment to subset-sum counting.

Approach

Let P be sum of numbers assigned +. Then P - (S-P) = target => 2P = S + target. If S+target is odd or |target|>S, answer is 0. Otherwise count subsets summing to P using 0/1 knapsack counting DP.

Why it works

Choosing which numbers are + uniquely determines signs; zeros naturally double counts via DP.

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

Idea

Convert +/- assignment to subset-sum counting.

Approach

Let P be sum of numbers assigned +. Then P - (S-P) = target => 2P = S + target. If S+target is odd or |target|>S, answer is 0. Otherwise count subsets summing to P using 0/1 knapsack counting DP.

Why it works

Choosing which numbers are + uniquely determines signs; zeros naturally double counts via DP.

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