Python || Math
Intuition\nIf sum of all the numbers considered till now is x, we can form all the numbers from 1 to x. This condition is True every time.\n\n# Approach\nKeep a
# Intuition\nIf sum of all the numbers considered till now is x, we can form all the numbers from 1 to x. This condition is True every time.\n\n# Approach\nKeep a variable limit which tracks till what max value we can form which is nothing but sum of all values considered till now.\nIf we encounter any number i.e. num which is greater than limit+1, it means we can\'t get any number between limit+1 to num-1.So we add limit+1 to our limit to extend our current limit and increase our answer count by 1 (Internally we are adding limit+1 to our array).Continue this process untill num is greater than limit+1.Meanwhile if at any moment limit >=ssum break off the loop.\nAfter considering all numbers from array , check if limit is still less than ssum and keep adding limit+1 and incrementing answer count to our limit till limit<ssum.\nNote : We need to necessarily add limit+1 every time and not any number greater than this as we can\'t form limit+1 using any of our previously considered numbers.\n\n# Complexity\n- Time complexity:\nO(n) \n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n    def minPatches(self, nums: List[int], ssum: int) -> int:\n        n=len(nums)\n        limit,cnt=0,0\n        for i in range(n):\n            if nums[i]>limit+1:\n                while nums[i]>limit+1:\n                    limit+=limit+1\n                    cnt+=1\n                    if limit>=ssum: break\n            limit+=nums[i]\n            if limit>=ssum: break\n        while limit<ssum:\n            limit+=limit+1\n            cnt+=1\n        return cnt\n\n```
['Math', 'Python', 'Python3']