Competitive ProgrammingEasy

Subset Sum

Detailed guide and Python implementation for the 'Subset Sum' problem.

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?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.