✔✔ Patching Array. Simple Solution with Explanation
\nint minPatches(vector<int>& nums, int n) {\n    long miss = 1, added = 0, i = 0;\n    while (miss <= n) {\n        if (i < nums.size() && nums[i] <= miss) {\n
```\nint minPatches(vector<int>& nums, int n) {\n    long miss = 1, added = 0, i = 0;\n    while (miss <= n) {\n        if (i < nums.size() && nums[i] <= miss) {\n            miss += nums[i++];\n        } else {\n            miss += miss;\n            added++;\n        }\n    }\n    return added;\n}\n```\n\nLet **miss** be the smallest sum in **[0,n]** that we might be missing. Meaning we already know we can build all sums in **[0,miss)**. Then if we have a number **num <= miss** in the given array, we can add it to those smaller sums to build all sums in **[0,miss+num)**. If we don\'t, then we must add such a number to the array, and it\'s best to add miss itself, to maximize the reach\n\n
[]