dsa · easy

Subset Sum Exists

GreyOrangeDynamic ProgrammingFoundation

Return whether a subset of nums sums to target. Each element at most once.

Arguments

**Example:** [3,34,4,12,5,2], target=9true (4+5).

Constraints

0 <= nums.length <= 100, 0 <= target <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[3,34,4,12,5,2]
9

Expected:
true

Example 2

Input:
[3,34,4,12,5,2]
30

Expected:
false

Open in the Dojo editor