O(1) Space O(input_arr.length) Time
\nclass RLEIterator {\n    int[] arr;\n    int idx;\n    public RLEIterator(int[] A) {\n        this.arr = A;\n        this.idx = 0;\n    }\n    \n    public in
```\nclass RLEIterator {\n    int[] arr;\n    int idx;\n    public RLEIterator(int[] A) {\n        this.arr = A;\n        this.idx = 0;\n    }\n    \n    public int next(int n) {\n        while (idx < arr.length) {\n            if (n > arr[idx]) {\n                n -= arr[idx];\n                idx += 2;\n            } else {\n                arr[idx] -= n;\n                return arr[idx + 1];\n            }\n        }\n        return -1;\n    }\n}\n```
[]