Signed Budget Ways
Preview mode. Log in to edit, run, submit, and save progress.
Signed Budget Ways
A budget review has several line items. For each item, the reviewer may keep it as a positive contribution or reverse it as a negative contribution. After assigning a plus or minus sign to every item, the signed sum must equal target. Count how many different sign assignments achieve that target. Choices are made per index, so equal values at different positions still represent different decisions. Input Format: You are given an integer array nums and an integer target. Output Format: Return the number of sign assignments that produce target.
Examples
nums = [1, 1, 1, 1, 1] target = 3
5
Explanation: Assignments reaching 3: +1 +1 +1 +1 -1; +1 +1 +1 -1 +1; +1 +1 -1 +1 +1; +1 -1 +1 +1 +1; -1 +1 +1 +1 +1. Count = 5, so the output is 5.
Approach hint
Track counts of reachable sums.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.