🚀 2-heap approach
ApproachWe use a 2-heap approach:
Sort the queries based on their start time.
Iterate through each num at num_index in nums:
2.1 For each query starting on or b
# Approach
We use a 2-heap approach:

1. Sort the queries based on their start time.
2. Iterate through each num at num_index in nums:
2.1 For each query starting on or before num_index, we push its end time into a max heap (using -end to simulate max-heap behavior).
2.2 We attempt to assign the current num task to a query interval in the max heap, respecting the constraint that a task needs num available slots.
2.3 We maintain a min heap of active end times for currently assigned intervals.
2.4 If the current num is larger than the number of available slots (heap size), it’s impossible to assign, so we return -1.
2.5 Also, we evict expired intervals from the min heap as we go.

The final answer is the number of queries we failed to use (m - result), where result tracks how many tasks were successfully assigned to a query interval.

# Complexity
- Time complexity:
O(mlogm+nlogm)
Sorting the queries takes 𝑂(𝑚log𝑚), and for each of the 𝑛 elements in nums, we push/pop from heaps at most 𝑂(log𝑚) time.

- Space complexity:
O(m)
We store up to m elements in the heaps.

# Code
```python3 []
# 2 heaps approach. TC: O(mlogm + nlogm) SC: O(m)
class Solution:
    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:
        n, m, min_heap, max_heap, queries_index = len(nums), len(queries), [], [], 0
        result = 0

        queries.sort()
        for num_index, num in enumerate(nums):
            while queries_index < m and num_index >= queries[queries_index][0]:
                _, end = queries[queries_index]
                heappush(max_heap, -end)
                queries_index += 1

            while max_heap and len(min_heap) < num:
                end = -heappop(max_heap)
                if end >= num_index:
                    heappush(min_heap, end)
                    result += 1
            
            if num > len(min_heap): return -1
            while min_heap and min_heap[0] <= num_index:
                heappop(min_heap)
        
        return m - result
```
['Python3']