Back to Practice Dashboard
Competitive ProgrammingEasy
Subset Sum
Learn how to solve the 'Subset Sum' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function is_subset_sum(arr, total) that returns True if there exists a subset of the non-negative integers in arr that sums to total, and False otherwise.
Constraints
- •1 <= len(arr) <= 100
- •0 <= arr[i] <= 1000
- •0 <= total <= 10000
Examples
Example 1
Input
is_subset_sum([3, 34, 4, 12, 5, 2], 9)
Output
True
Explanation
The subset {4, 5} sums to 9.
Example 2
Input
is_subset_sum([3, 34, 4, 12, 5, 2], 30)
Output
False
Explanation
No subset sums to 30.
Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.