Algorithms and Data Structures · Middle · Question 75 of 75

Subset sum: can some of the numbers add up to target? What is the classic DP solution?

Explanation

reachable[s] says whether sum s can be formed; for each number, update sums from high to low so it's used once. Greedy can miss solutions, and permutations are O(n!). The DP is pseudo-polynomial: fast only while target is small.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 75

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz