1/45
Loading...
...Scale Balance Problem
We have 5 weights [1,1,1,1,1]. Place each on left(+) or right(-) to make weight difference exactly 3. We'll explore all 2^5=32 cases using DFS.
🔒
Loading...
We have 5 weights [1,1,1,1,1]. Place each on left(+) or right(-) to make weight difference exactly 3. We'll explore all 2^5=32 cases using DFS.
You have n weights. You want to place each weight on either the left(+) or right(-) side of a scale to achieve a target weight difference. Given an array weights containing the weight values and a target difference, find the number of ways to place the weights to achieve the target difference.
weights = [1, 1, 1, 1, 1], target = 3
5
Left-Right placements: (-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.