Classic Two Heaps Solution || Java || Clean Code || Not so easy
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:\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```java []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        final int n = nums.length;\n        final int m = queries.length;\n\n        Arrays.sort(queries, (a, b) -> a[0] - b[0]);\n\n        final PriorityQueue<Integer> minHeap = new PriorityQueue<>((a, b) -> a - b);\n        final PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);\n\n        int used = 0;\n\n        for (int i = 0, j = 0; i < n; i++) {\n            while(j < m && queries[j][0] == i) {\n                maxHeap.add(queries[j++][1]);\n            }\n\n            nums[i] -= minHeap.size();\n\n            while(nums[i] > 0 && !maxHeap.isEmpty() && maxHeap.peek() >= i) {\n                minHeap.add(maxHeap.remove());\n\n                used++;\n                nums[i]--;\n            }\n\n            if (nums[i] > 0) return -1;\n\n            while(!minHeap.isEmpty() && minHeap.peek() == i) {\n                minHeap.remove();\n            }\n        }\n\n        return m - used;\n    }\n}\n```
['Java']