Readable Javascript Solution
Javascript solution of https://leetcode.com/problems/rle-iterator/discuss/168294/Java-Straightforward-Solution-O(n)-time-O(1)-space\n\nTo me, this seems like a 
Javascript solution of https://leetcode.com/problems/rle-iterator/discuss/168294/Java-Straightforward-Solution-O(n)-time-O(1)-space\n\nTo me, this seems like a greedy problem\nGreedy choice: retire many number as possible.\n\n```\nvar RLEIterator = function(A) {\n    this.A = A;\n    this.index = 0;\n};\n\nRLEIterator.prototype.next = function(n) {\n    while (this.index < this.A.length && n > this.A[this.index]) {\n        n -= this.A[this.index];\n        this.index += 2;\n    }\n    \n    if (this.index < this.A.length) {\n        this.A[this.index] -= n;\n        return this.A[this.index + 1];\n    }\n    \n    return -1;\n};\n```
[]