dsa · easy
Subset Sum Exists
GreyOrangeDynamic ProgrammingFoundation
Return whether a subset of nums sums to target. Each element at most once.
Arguments
nums— the input array of integerstarget— the value you are searching for or summing to
**Example:** [3,34,4,12,5,2], target=9 → true (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