Problem
Ask
Submissions

Problem: Find K-Sum Subsets

med
30 min
Explore how to find all subsets of distinct positive integers that add up to a target sum k. Understand the problem constraints and implement an optimal solution running in O(n * 2^n) time and O(n) space, building a foundation for solving similar subset problems in coding interviews.

Statement

Given an array of nn distinct positive integers, find all possible subsets of these integers such that the sum of the elements in each subset equals a given target value k.

Return a 2D array, where each inner array represents a subset whose sum equals k.

Constraints:

  • 1n101 \leq n \leq 10

  • 1x1001 \leq x \leq 100, where xx is any member of the input array.

  • 11 \leq k 103\leq 10^3

Problem
Ask
Submissions

Problem: Find K-Sum Subsets

med
30 min
Explore how to find all subsets of distinct positive integers that add up to a target sum k. Understand the problem constraints and implement an optimal solution running in O(n * 2^n) time and O(n) space, building a foundation for solving similar subset problems in coding interviews.

Statement

Given an array of nn distinct positive integers, find all possible subsets of these integers such that the sum of the elements in each subset equals a given target value k.

Return a 2D array, where each inner array represents a subset whose sum equals k.

Constraints:

  • 1n101 \leq n \leq 10

  • 1x1001 \leq x \leq 100, where xx is any member of the input array.

  • 11 \leq k 103\leq 10^3