Clean Python solution with explanation using Bisect Left / Binary Search
Idea is simple:\nA = [3,8,0,9,2,5]\ncounts[i] keeps count of numbers that need to be removed before A[2i + 1] can be removed\ncounts = [3, 3, 5]\nIf we are aske
Idea is simple:\nA = [3,8,0,9,2,5]\ncounts[i] keeps count of numbers that need to be removed before A[2i + 1] can be removed\ncounts = [3, 3, 5]\nIf we are asked to remove 4 numbers, All we need to do is bisect left counts array for 4. Bisect left gives us i = 2 which corresponds to 2i + 1 in A, which is 5. So, 5 is our answer.\n```\nfrom bisect import bisect_left as bl\nclass RLEIterator:\n\n    def __init__(self, A: List[int]):\n        self.A = A\n        self.removed = 0\n        self.counts = A[::2]\n        for i in range(1, len(self.counts)):\n            self.counts[i] += self.counts[i-1]\n        self.total = self.counts[-1] if self.counts else 0\n\n    def next(self, n: int) -> int:\n        if self.removed >= self.total:\n            return -1\n        self.removed += n\n        i = bl(self.counts, self.removed)\n        if i >= len(self.counts):\n            return -1\n        return self.A[2*i+1]\n\t\t```
[]