Java easy to understand solution
\nclass RLEIterator {\n    int A[];\n    int index = 0;//indicate the current start of the array(number of times)\n    public RLEIterator(int[] A) {\n        th
```\nclass RLEIterator {\n    int A[];\n    int index = 0;//indicate the current start of the array(number of times)\n    public RLEIterator(int[] A) {\n        this.A = A;\n    }\n    \n    public int next(int n) {\n        while(index + 1 < A.length){//valid\n            if(n > A[index]){\n                n -= A[index];\n                index += 2;\n            }else {//smaller or equal\n                A[index] -= n;\n                return A[index + 1];\n            }\n        }\n        return -1;\n    }\n}\n```
[]