1/55
Loading...
🎯Budget Adjustment
Find ways to reach sum 3 by applying + or - to each number in [1, 1, 1, 1, 1]. Example: +1+1+1+1-1 = 3
🔒
Loading...
Find ways to reach sum 3 by applying + or - to each number in [1, 1, 1, 1, 1]. Example: +1+1+1+1-1 = 3
You have n non-negative integers. You want to make a targetChange number by appropriately adding or subtracting these budgets. Given an array budgets containing the available integers and a targetChange number, find the number of ways to make the targetChange number by adding and subtracting.
budgets = [1, 1, 1, 1, 1], targetChange = 3
5
-1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 There are 5 ways in total.