Skip to main content

Target Sum

Given an array of integers and a target sum Assign + or - to each number to reach the target Return the number of different ways to achieve this Example: nums = [1,1,1,1,1], target = 3 => 5 ways (+1+1+1+1+1 = 5, +1+1+1-1-1 = 1, etc.)

Target Sum is a dynamic programming question: define the state cleanly and the transitions usually follow. Interviewers love it because it reveals your state-and-transition thinking and your edge-case discipline. Don't rush the code—spend your time nailing the state definition first.

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.

1Count Ways to Reach Target Summedium
Based onLeetCode

Get a note when something new lands

New company guides, new problems and big changes to Coco. Rare, and you can leave any time. By joining you agree to get these emails.