You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.
An integer x is obtainable if there exists a subsequence of coins that sums to x.
Return the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.
A subsequence of an array is a new non-empty array formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.
Example
Input: coins = [1,4,10], target = 19
Output: 2
Explanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10]. It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added.
The key idea is to greedily maintain the smallest continuous range of sums we can already form, say [1, reach]. If the next coin value is at most reach + 1, we can extend the reachable range to reach + coin. Otherwise, there is a gap at reach + 1, so we should add a coin of value reach + 1, which maximizes the newly covered range. Repeating this until reach reaches target gives the minimum number of added coins. This is the classic patching array greedy strategy.