A finance dashboard lists budget adjustments in amounts. Each adjustment must be applied either as a credit (+) or as a debit (-).
Write countSignChoices(amounts, target) that returns how many ways there are to give every amount a sign so that the signed amounts add up to target.
Two ways are different if at least one position has a different sign, even when the amounts are equal (so [0] with target 0 has 2 ways).
Input: amounts = [1,1,1,1,1], target = 3 Output: 5
Exactly one of the five 1s must be negative, and there are 5 ways to choose which.
Input: amounts = [2,3], target = 1 Output: 1
Only -2 + 3 gives 1.
1 <= amounts.length <= 150 <= amounts[i] <= 100-1500 <= target <= 1500Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #289 Signed Budget Adjustments. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.