Javascript recursion. Runtime O(N), space O(1);
\nvar RLEIterator = function(A) {\n    this.A = A;\n    this.index = 0;\n};\n\n/** \n * @param {number} n\n * @return {number}\n */\nRLEIterator.prototype.next 
```\nvar RLEIterator = function(A) {\n    this.A = A;\n    this.index = 0;\n};\n\n/** \n * @param {number} n\n * @return {number}\n */\nRLEIterator.prototype.next = function(n) {\n    let diff = n - this.A[this.index];\n    if(diff <= 0) {\n        this.A[this.index]-=n;\n        return this.A[this.index+1];\n    } else {\n        this.index += 2;\n        if(this.index >= this.A.length) {\n            return -1;\n        }\n        return this.next(diff);\n    }\n};\n```
['Recursion', 'JavaScript']