C++ Solution using Heap and Sorting | Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nFor every index try to choose the seqment that covers that index also which is the fart
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFor every index try to choose the seqment that covers that index also which is the farthest.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is explained along with the code \n\n# Complexity\n- Time complexity: n log(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& q) {\n        priority_queue<int> availableQ; // Max Heap\n        priority_queue<int, vector<int>, greater<int>> appliedQ; // Min Heap\n\n        // To get all the queries in a sequence\n        sort(q.begin(), q.end());\n\n        int qIdx = 0;\n        int len = nums.size();\n        int qLen = q.size();\n        int successfullyAppliedQueries = 0;\n\n        for(int i = 0; i < len; i++){\n            // Get all the queries which can effect current idx\n            // And store the end of the querie in the maxHeap which will return the \n            // highest range query at the top\n            while(qIdx < qLen and q[qIdx][0] == i){\n                availableQ.push(q[qIdx][1]);\n                qIdx++;\n            }\n\n            // appliedQ store the all the applied queries on this index\n            // which means this many queries is effecting this perticular index\n            nums[i] -= appliedQ.size();\n\n\n            // new apply all the available queries and store them in the applied queue (min heap)\n            // we are using the queries till the current idx become zero or there are no queries\n            // available to use\n            // availableQ may have more queries then needed so use till the current idx is > 0 \n            while(nums[i] > 0 and not availableQ.empty() and availableQ.top() >= i){\n                successfullyAppliedQueries++;\n                appliedQ.push(availableQ.top());\n                availableQ.pop();\n                nums[i]--;\n            }\n\n            // after applying all the queries if still current idx is not zero then it\'s not\n            // possiable to make it a zero array\n            if (nums[i] > 0) return -1;\n\n            // now remove all the applied queries for which the range is ended\n            // Min Heap is used for this only to get the smallest range at top and remove it\n            while(not appliedQ.empty() and appliedQ.top() == i){\n                appliedQ.pop();\n            }\n        }\n\n        return qLen - successfullyAppliedQueries;\n    }\n};\n```
['Sorting', 'Heap (Priority Queue)', 'C++']