MEDIUMasked at 5 companies

Target Sum

A medium-tier problem at 51% community acceptance, tagged with Array, Dynamic Programming, Backtracking. Reported in interviews at Myntra and 4 others.

Founder's read

Target Sum is a medium-difficulty problem that shows up in OAs from Google, Salesforce, Pinterest, and others. You're given an array of positive integers and a target sum. Your job: assign a plus or minus sign to each number so the result equals the target. It sounds simple until you realize the brute force approach (2^n possibilities) will time out instantly. The trick is recognizing this as a subset-sum variant, which pivots to dynamic programming. If this problem hits your live assessment and you freeze on the DP formulation, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
5
Difficulty
MEDIUM
Acceptance
51%

Companies that ask "Target Sum"

If this hits your live OA

Target Sum is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

Most candidates try backtracking first because the problem description screams 'try all sign combinations.' That works for tiny arrays but fails at scale. The real insight: reframe the problem. If you assign plus to some numbers and minus to others, you can split the array into two groups. Math shows that if one group sums to P and the other to N, then P minus N equals your target. This transforms Target Sum into a classic subset-sum DP problem: find how many subsets sum to a specific value. Build a DP table where dp[i] represents the count of ways to achieve sum i. Iterate through each number and update the table backward to avoid double-counting. StealthCoder becomes your safety net if you blank on the transformation or the DP table mechanics during the timed assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Target Sum recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Target Sum interview FAQ

Is this problem still asked at big tech companies?+

Yes. Google, Salesforce, and Pinterest all report asking it. The acceptance rate sits around 51%, meaning roughly half the candidates who attempt it pass. That gap often comes down to whether you spot the DP reframe or get stuck on backtracking.

What's the main trick?+

Reframe it as a subset-sum problem. Instead of 'assign plus or minus to each number,' ask 'which numbers go in the plus group?' Then use DP to count ways to hit a specific sum. This avoids the 2^n brute force explosion.

How does this relate to Dynamic Programming and Backtracking?+

Backtracking is the naive approach: explore all 2^n sign assignments. DP is the correct optimization. You build a table iteratively, reusing subproblem results. The problem tests whether you can recognize when backtracking will fail and pivot to DP.

What's the time complexity I should target?+

O(n * sum) where n is array length and sum is the range of possible sums. This is polynomial and passes. The backtracking approach is O(2^n), which will time out on arrays larger than about 20 elements.

Can I solve this in multiple languages?+

Yes. The DP logic is language-agnostic. Python, Java, C++, and JavaScript all handle it the same way. The challenge is the algorithmic insight, not the syntax.

Want the actual problem statement? View "Target Sum" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.