Back to course home
0% completed
Solution: Subset Sum Equal to Target
Problem Statement
Given an array nums
containing n
integers, return the number of subsets having a sum equal to x
.
A subset can be any combination of numbers from the array, including an empty subset. However, you need to consider all possible combinations to determine the exact number of subsets with a sum equal to x
.
Examples
Example 1:
- Input: nums =
[1, 2, 3, 4, 5]
, x =5
- Expected Output:
3
- Explanation: The subsets that sum to 5 are
[5]
,[1, 4]
, and[2, 3]
.
Example 2:
- Input: nums =
[2, 4, 6, 10]
, x =16
.....
.....
.....
Like the course? Get enrolled and start learning!