values and an integer goal. Put a + or a - in front of every number, then add up the resulting terms.
How many sign assignments make the total equal goal? Two assignments differ if at least one element gets a different sign, even when that element is zero.values=[2, 3, 5], goal=0 → 2
Both +2 +3 -5 and -2 -3 +5 work.
values=[4, 0, 1], goal=3 → 2
We need +4 -1; the zero can take either sign, so there are two ways.
values=[6], goal=4 → 0
values=[2, 3, 5], goal=0
2
Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.