Given an array of positive integers and a target sum, determine whether there exists a subset whose sum equals the target. This is the classic subset-sum decision problem and a foundational knapsack transformation.
nums = array of positive integers, target = required sum
true if some subset sums to target, otherwise false
Example 1:
Input:
nums = [3,34,4,12,5,2] target = 9
Output:
true
Explanation:
A subset like 4 + 5 sums to 9.
Example 2:
Input:
nums = [1,2,3] target = 7
Output:
false
Explanation:
No subset can reach 7.