BEATS 100% || Java Solution || Optimum Solution
Intuition\n- The problem aims to determine the maximum number of elements that can be removed from an array given a set of constraints defined by queries. Each 
# Intuition\n- The problem aims to determine the maximum number of elements that can be removed from an array given a set of constraints defined by queries. Each query specifies a range within which removals can be made. The goal is to ensure that the constraints are satisfied while maximizing the number of elements removed.\n\n# Approach\n- Sort the Queries: The queries are sorted based on their starting index. This helps in processing them in a sequential manner.\n\n- Priority Queue for End Points: A max-priority queue (max-heap) is used to keep track of the end points of the active queries. This allows efficient retrieval of the maximum end point.\n\n- Difference Array: A difference array diffs is maintained to track the number of removals to be adjusted.\n\n- Processing Elements:\n\n  - For each element in the nums array, the current difference (cur) is adjusted using the difference array.\n\n  - While the current removals are less than the required removals (nums[i]), the max-heap is used to find a range that can still be used for removals, and adjustments are made to the difference array.\n\n  - If it\'s impossible to satisfy the removal requirement for any element, the function returns -1.\n\n# Complexity\n- Time complexity: `O(Q*logQ)`\n\n- Space complexity: `O(N*logQ)`\n\n# Code\n```java []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        Arrays.sort(queries, (a, b) -> a[0] - b[0]);\n        PriorityQueue<Integer> last = new PriorityQueue<>((a, b) -> b - a);\n        int[] diffs = new int[nums.length + 1];\n        int idx = 0;\n        int cur = 0;\n        for(int i=0; i<nums.length; i++) {\n            while(idx < queries.length && queries[idx][0] == i) {\n                last.add(queries[idx][1]);\n                idx++;\n            }\n            cur += diffs[i];\n            while(cur < nums[i] && !last.isEmpty() && last.peek() >= i) {\n                cur++;\n                diffs[last.poll() + 1]--;\n            }\n            if(cur < nums[i]) {\n                return -1;\n            }\n        }\n        return last.size();  \n    }\n}\n```
['Sorting', 'Heap (Priority Queue)', 'Java']