Subset Sum - aloalgo.com

Subset Sum

Medium
New!

You are given a collection of non-negative integers and a specific target sum.

Your task is to determine if it's possible to find a subset of these integers that, when added together, perfectly equals the given target sum. Return true if such a subset exists, and false otherwise.

You can assume that each integer from the given collection can be used at most once in your chosen subset.

Example 1

Inputs
numbers = [3, 34, 4, 12, 5, 2]
target = 9
Output
True
Explanation:

A subset [4, 5] sums to 9.

Example 2

Inputs
numbers = [3, 34, 4, 12, 5, 2]
target = 30
Output
False
Explanation:

No subset of the given numbers sums to 30.

Example 3

Inputs
numbers = [1, 2, 3]
target = 6
Output
True
Explanation:

The subset [1, 2, 3] sums to 6.

Loading...

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!