0ms
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:o(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long minPatches(vector<int>& a, int n) {\n\n        long long i,j=0,ans=0,k=0,m;\n        a.push_back(INT_MAX);\n\n        for(i=0;i<a.size();i++)\n        {\n            if(a[i]>n)a[i]=n+1;\n            if(a[i]>k)\n            {\n                j=k+1;\n                m=a[i]-1;\n                while(k<m)\n                {\n                    k+=k+1;\n                    ans++;\n\n\n                }\n\n            }\n            \n            k+=a[i];\n            if(k>=n) break;\n        }\n        return ans;\n        \n    }\n};\n```\n![image.png](https://assets.leetcode.com/users/images/5c1b94c4-fc51-4eae-9b9c-25e7ae88b456_1718515148.3065598.png)\n
['C++']