Should be medium greedy+: min+max heaps
This should be something like google medium on the harder end of mediums.\n\nGreedy logic: for each i in [0, N) pick a query with the farthest end. Why? Because
This should be something like `google medium` on the harder end of mediums.\n\nGreedy logic: for each `i in [0, N)` pick a query with the farthest end. Why? Because it will cover bigger ranges!\n\nImplementation is also a `piece of art`...\n\n1. group query starts by end: `start[0].append([0,1],[0,2],[0,5]])`\n2. Create 2 groups: `candidates` (sorted by max_end) and `picked` (sorted by min_end)\n3. add to the `candidates` ends with `start[i]`\n4. pick from the `candidates` ends until you get the size of the `picked` group >= nums[i]\n5. remove shorter candidates from `picked` group\n6. return total_queries - picked\n\nP.S. We can also just sort the queries by `start,-end` instead of `query_start` DS, but it\'s much slowers during runtime.\n\n```\nclass Solution:\n    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:\n        query_start = defaultdict(list)\n        for s,e in queries: # 1\n            query_start[s].append(e)\n        picked_min_end = [] # 2\n        candidates_max_end = [] # 2\n        used = 0\n        for i in range(len(nums)):\n            for e in query_start[i]: # 3\n                heappush(candidates_max_end, -e)\n            while picked_min_end and picked_min_end[0] < i: # 5\n                heappop(picked_min_end)\n            while candidates_max_end and len(picked_min_end) < nums[i]: # 4\n                furthest_end = -heappop(candidates_max_end)\n                if furthest_end >= i: # ignore end < i\n                    heappush(picked_min_end, furthest_end)\n                    used += 1\n            nums[i] -= len(picked_min_end)\n            if nums[i] > 0:\n                return -1\n        return len(queries) - used\n```
['Greedy', 'Heap (Priority Queue)', 'Python3']