C++ || SIMPLE SOLUTION || O(n) || Easy To Understand
first copy all elements in another vector then \nStart understanding from the nested if else \n\n\n\nclass RLEIterator {\n    private: vector<int>v;\npublic:\n 
first copy all elements in another vector then \nStart understanding from the nested if else \n\n```\n\nclass RLEIterator {\n    private: vector<int>v;\npublic:\n   long long int size(vector<int>&v)\n    {\n       long long int n=0;\n        for(int i=0;i<v.size();i=i+2)\n            n+=v[i];\n        return n;\n    }\n    RLEIterator(vector<int>& encoding) {\n        for(int i=0;i<encoding.size();i++)\n            v.push_back(encoding[i]);\n    }\n    \n    int next(int n) {\n         if(v.size()==0||n>size(v))\n      { v.clear();      \n             return -1;}\n        if(n<v[0])                           //from here\n        {\n            v[0]=v[0]-n;\n            return v[1];\n        }\n        else if(n==v[0])\n        {\n            int temp=v[1];\n            auto it=v.begin();\n            auto jt=v.begin()+2;\n            v.erase(it,jt);\n            return temp;\n        }\n        else {\n             if(n>size(v))\n           { v.clear();      \n             return -1;}\n             auto it=v.begin();\n             auto jt=v.begin()+2;\n             n=n-v[0];\n             v.erase(it,jt);\n             return next(n);\n        }\n    }\n};\n```
[]