Java modular solution (5 ms, faster than 92%)
Lengthy, but easy to understand solution\n\nclass RLEIterator {\n\n\tint[] encoding;\n\tint index;\n\n    public RLEIterator(int[] encoding) {\n        this.enc
Lengthy, but easy to understand solution\n```\nclass RLEIterator {\n\n\tint[] encoding;\n\tint index;\n\n    public RLEIterator(int[] encoding) {\n        this.encoding = encoding;\n        this.index = 0;\n    }\n\n    public int next(int n) {\n\t\t// remove the first n-1 elements\n        this.remove(n - 1);\n\t\t\n\t\t// remove any prefix zeroes\n        this.removePrefixZeroes();\n\t\t\n\t\t// peek the latest value\n        int res = this.peek();\n\t\t\n\t\t// now remove the last value i.e. nth value\n        this.remove(1);\n\n        return res;\n    }\n\n\t// removes n values\n    private void remove(int n) {\n        for (int i = n; i > 0; ) {\n            this.removePrefixZeroes();\n            if (this.index >= this.encoding.length) return;\n            if (this.encoding[this.index] <= i) {\n                i -= this.encoding[this.index];\n                this.index += 2;\n            } else {\n                this.encoding[this.index] = this.encoding[this.index] - i;\n                i = 0;\n            }\n        }\n    }\n\n\t// removes any prefix 0s, such as 0,9\n    private void removePrefixZeroes() {\n        if (this.index >= this.encoding.length) return;\n        if (this.encoding[this.index] == 0) {\n            this.index += 2;\n            this.removePrefixZeroes();\n        }\n    }\n\n\t// just take a peek at the value, don\'t remove it\n    private int peek() {\n        if (this.index >= this.encoding.length) return -1;\n        return this.encoding[this.index + 1];\n    }\n}\n```
['Java']