Finding Redundant Queries using minHeap and maxHeap
# Intuition\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(Q * LogQ + N)\nwhere Q = Count of Queries, N = Length of Nums\n- Space complexity:\nO(Q) where Q = Count of Queries\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) \n    {\n        int n = nums.size(), qLen = queries.size() ;\n\n        priority_queue<int> maxHeap ; // All valid candidates\n        priority_queue<int, vector<int>, greater<int>> minHeap ; // All chosen candidates\n\n        int cnt = 0 ; // Keeps track of all the queries used till date\n        int j = 0 ; // Traversing over queries[]\n\n        // We need to get the queries in sorted order based on startingIndex\n        sort(queries.begin(), queries.end() ) ; \n\n        for(int i = 0 ; i < n ; i++)\n        {\n            // 1. Choosing all the valid Queies for the currentIndex\n            while(j < qLen && queries[j][0] == i)\n            {\n                maxHeap.push(queries[j][1]) ;\n                j++ ;\n            }\n\n            // 2. Decrementing nums[i] by the no of queries still left to be processed\n            nums[i] -= (int) minHeap.size() ; \n\n            // 3. Pushing all the queries which are required to decrement nums[i] to 0\n            while(!maxHeap.empty() && maxHeap.top() >= i && nums[i] > 0) \n            {\n                nums[i]-- ;\n                minHeap.push(maxHeap.top() ) ;\n                maxHeap.pop() ;\n                cnt++ ;\n            }\n\n            // 4. If we cannot decrement nums[i], we return -1\n            if(nums[i] > 0)  return -1 ;\n\n            // 5. We remove all such queries which cannot contribute going further\n            while(!minHeap.empty() && minHeap.top() <= i)  minHeap.pop() ;\n        }\n\n        return qLen - cnt ;\n    }\n};\n```
['Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++']