Problem
You get an integer array nums and an integer target. Put a + sign or a - sign in front of each item in nums. Then add the signed items.
Return the number of different sign choices that give the sum target. Two choices are different when at least one item has a different sign.
Example 1
- Input:
- nums = [2,1,1], target = 2
- Output:
- 2
- Explanation:
+2 + 1 - 1and+2 - 1 + 1both give 2.
Example 2
- Input:
- nums = [3,5], target = 1
- Output:
- 0
- Explanation:
- The four possible sums are 8, 2, -2 and -8.
Example 3
- Input:
- nums = [0,4], target = 4
- Output:
- 2
- Explanation:
- The sign in front of 0 does not change the sum. So
+0 + 4and-0 + 4both count.
Constraints
- 1 <= nums.length <= 20
- 0 <= nums[i] <= 1000
- 0 <= sum(nums) <= 1000
- -1000 <= target <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Partition Equal Subset Sum
Coding · 0-1 Knapsack · Array · Dynamic Programming
- Last Stone Weight II
Coding · 0-1 Knapsack · Array · Dynamic Programming
- Beautiful Arrangement
Coding · Array · Backtracking · Bit Manipulation
- Coin Change
Coding · Array · Breadth-First Search · Complete Knapsack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Meta
Leetcode 494. Target Sum
Reported Nov 1, 2025 · 2 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Pinterest
Target Sum
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 77.6. This is not an interview probability.
View sourcePinterest
Target Sum
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 72.9. This is not an interview probability.
View source