Target Sum Problem

Target Sum Problem — ExecCode Medium DSA Practice

Solve the Target Sum problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You are given an integer array nums and an integer target. Add a + or − before each number. Return the number of ways to assign signs so the expression equals target.

Examples

Input nums = [1, 1, 1], target = 1; Output 3. Input nums = [1, 1, 1, 1, 1], target = 3; Output 5. Input nums = [1], target = 1; Output 1

Constraints

1 ≤ nums.length ≤ 20 0 ≤ nums[i] ≤ 1000 −1000 ≤ target ≤ 1000

Practice Target Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.