C++ solution- trick is NOT to create the actual array from the encoding
As described in the title, I was creating a vector of original items from encoding and then applying the operation of next on it. It gave me TLE. So just keep t
As described in the title, I was creating a vector of original items from encoding and then applying the operation of next on it. It gave me TLE. So just keep the encoding as it is and do the math on current index.\n```\nclass RLEIterator {\npublic:\n    int index;\n    vector<int> e;\n    RLEIterator(vector<int>& encoding) {\n        index=0;\n        e = encoding;\n    }\n    \n    int next(int n) {\n        while(index<e.size())\n        {\n            if(e[index]>=n)\n            {\n                e[index]-=n;\n                return e[index+1];\n            }\n            else\n            {\n                n-=e[index];\n                index+=2;\n            }\n        }\n        return -1;\n    }\n};\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator* obj = new RLEIterator(encoding);\n * int param_1 = obj->next(n);\n */\n ```
['C']