🔥Explained :🔥 🔥 c++🔥  🔥sorting 🔥 🔥100% faster🔥 🔥Tricky🔥💯💯 ⬆⬆⬆
Intuition\n Describe your first thoughts on how to solve this problem. \n1. if we can make all number from 1 to n, and nums[i] = 5 => then we can make all numbe
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. if we can make all number from 1 to n, and nums[i] = 5 => then we can make all number from 1 to n+5\n\n2. if we can make (1 to n) then we need to make the next number i.e n+1;\n\n3. **Case-1 :**  the current number (i.e `nums[i] > required` ) then we need to add the required number in the nums array. \n    in this case `count++` and our next required number will be `2*required` . \n\n4.  **Case-2 :**   the current number is less than required (i.e `nums[i] < required`)   then our next required number will be `required + nums[i]`\n\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n log(n))$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int minPatches(vector<int>& nums, int n) {\n        long long  ans = 0, required = 1;\n        sort(nums.begin(), nums.end());\n\n        for(int i=0; i<nums.size(); i++)   {\n            if(required > n)   return ans;\n            if(required < nums[i]) {\n                ans++;\n                required *= 2;\n                i--;\n            }\n            else    \n                required += nums[i];\n        }\n\n        while(required <= n)    {\n            ans++;\n            required *= 2;\n        }\n\n        return ans;\n    }\n};\n```
['C++']