[Java] O(n) | Straight Forward
\nclass RLEIterator {\n    int[] arr;\n    int index;\n    public RLEIterator(int[] encoding) {\n        arr = encoding;\n        index = 0;\n    }\n    \n    p
```\nclass RLEIterator {\n    int[] arr;\n    int index;\n    public RLEIterator(int[] encoding) {\n        arr = encoding;\n        index = 0;\n    }\n    \n    public int next(int n) {\n        int curr = 0;\n\t\t\n\t\t// Exhausting the next n elements\n        while(index < arr.length && arr[index] < n) {\n            n -= arr[index];\n            arr[index] = 0;\n            index += 2;\n        }\n        \n\t\t// No elements left\n        if(index + 1 >= arr.length) return -1;\n\t\t\n\t\t// Update the current value\n        arr[index] -= n;\n        \n        return arr[index + 1];\n    }\n}\n\n```
['Java']