Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Question Description

(This question is a variation of the LeetCode question 39. Combination Sum. If you haven't completed that question yet, it is recommended to solve it first.)

Given a list of positive integers and a target number k, write a function that returns true if there exists a subset of nums that adds up to k, and false otherwise. Note that numbers can appear more than once in the list.

Constraints:

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 10610^6
  • 1 <= k <= 10910^9
Test Cases
Input
Output
Expected