Free written solutionPatching Array (LeetCode 330): Solution and Explanation
Add as few numbers as possible to a sorted array so that every value from 1 to n is the sum of some subset. The whole problem collapses to one number: the largest reach such that everything in [1, reach] is already formable.
Read the intuition, approach, code and complexity →