Target Sum
You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums. Return the number of different expressions that you can build, which evaluates to target.

30:00

Target Sum
medium
Topics
Companies

You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums. Return the number of different expressions that you can build, which evaluates to target.

Example 1:
Input: {"nums":[1,1,1,1,1],"target":3}
Output: 5
Constraints:
  • 1nums.length201 \leq \text{nums.length} \leq 20

  • 0nums[i]10000 \leq \text{nums}[i] \leq 1000

  • 0nums[i]10000 \leq \sum \text{nums}[i] \leq 1000

  • 1000target1000-1000 \leq \text{target} \leq 1000

Input
arr ={"nums":[1,1,1,1,1],"target":3}

Find ways to reach target 3 using +/- signs

Target: 3
Found: 0 ways
Numbers Array
[0]

1

[1]

1

[2]

1

[3]

1

[4]

1

Current Expression

(empty) = 0

Exploring at index -1
+undefined → sum=NaN
-undefined → sum=NaN

Total ways to reach target 3: 0

Variables
No variables to display
DepthFunction Call
Stack empty
0/51