Simp[le Commented Code, multiple Priority Queue approach
Complexity

Time complexity:
O(N*logN)


Space complexity:
O(N)

Code
# Complexity\n- Time complexity:\nO(N*logN)\n\n- Space complexity:\nO(N)\n\n# Code\n```python3 []\nclass Solution:\n    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:\n        queries.sort(key = lambda x: x[0]) # sort based on start index\n        queries = deque(queries) # deque makes popping faster\n        queries.append([float(\'inf\'), float(\'inf\')]) # so we can avoid if cond in the while loop\n        pq = [] # pq will contain valid endpoints thus far\n        options = [] # these are the next options\n        for i, num in enumerate(nums):\n            while pq and pq[0] < i: # pop endpoints that won\'t count anymore\n                heapq.heappop(pq)\n            while queries[0][0] <= i: # any option that starts now or earlier is valid\n                _, end = queries.popleft()\n                heapq.heappush(options, -1*end) # -1*end since we\'re in \n            for _ in range(max(0, num - len(pq))): # if 0 >= num - len(pq) we\'re good\n                if not options or -1 * options[0] < i:\n                    return -1 # we ran out of options\n                heapq.heappush(pq, -1*heapq.heappop(options))\n        return len(options) # these are the options we didn\'t use\n```
['Greedy', 'Heap (Priority Queue)', 'Python3']