1146. Subset Sum Problem

EasyDynamic Programming0/1 Knapsack

Given an array nums of non-negative integers and a target, determine whether any subset sums exactly to the target. Return true or false. The input is JSON {nums, target}.

Input: JSON {nums, target}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"nums":[3,34,4,12,5,2],"target":9}
Output: true
Explanation: 4+5 = 9.
Example 2
Input: {"nums":[3,34,4,12,5,2],"target":30}
Output: false
Explanation: No subset sums to 30.
Example 3
Input: {"nums":[1,2,3],"target":0}
Output: true
Explanation: The empty subset.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →