Javascript Solution beating 100% in O(1) space and O(n) time
Looking at the solution, seems like a simple producer consumer problem.\n\nnext(n) \nshould first produce i.e. iterate n places\nthen check while n is less than
Looking at the solution, seems like a simple producer consumer problem.\n\nnext(n) \nshould first produce i.e. iterate n places\nthen check while n is less than allowed limit\nkeep consuming\n\nif you are out of bound return -1\n\nor else return next position\n\n```\n/**\n * @param {number[]} encoding\n */\nvar RLEIterator = function(encoding) {\n    this.arr = encoding\n    \n    this.itrSum = 0\n    this.itrPtr = 0\n};\n\n/** \n * @param {number} n\n * @return {number}\n */\nRLEIterator.prototype.next = function(n) {\n\t// PRODUCE\n    this.itrSum += n\n    \n\t// IF ABOVE LIMIT CONSUME\n    while (this.arr[this.itrPtr] < this.itrSum) {\n        this.itrSum -= this.arr[this.itrPtr]\n        this.itrPtr += 2\n    }\n    \n\t// OUT OF BOUNDS\n    if (this.itrPtr >= this.arr.length) {\n        return -1\n    }\n    \n\t// RETURN NEXT\n    return this.arr[this.itrPtr+1]\n};\n\n/** \n * Your RLEIterator object will be instantiated and called as such:\n * var obj = new RLEIterator(encoding)\n * var param_1 = obj.next(n)\n */\n```\n\nP.S. This is my first try at LC\'s discuss so please any feedback helps me! Thanks!
['JavaScript']