Subset sum
MediumGiven an array of non-negative numbers, find if there is a subset of any numbers in the array that add up to a given sum.
For example, if your function is given the following inputs:
arr = [1, 5, 3]total = 4
The output should be
True
since 1 + 3 = 4
.But if you're given:
arr = [2, 3, 5]total = 4
Your function should return
False
.Try it
Solution
8 Essential Recursion & Dynamic Programming Coding Interview Problems
Master Recursion & Dynamic Programming by trying the coding challenges below.
- 1.FibonacciEasy
- 2.Unique pathsMedium
- 3.KnapsackMedium
- 4.Subset sumMedium
- 5.Power setMedium
- 6.Coin changeMedium
- 7.Word breakHard
- 8.Longest common subsequenceHard