Easy understanding solution
Easy understanding Java solution using pointer with detailed description.\nTime Complexity: O(n)\nSpace Complexity: O(1)\n\n\nclass RLEIterator {\n    \n    // 
Easy understanding Java solution using pointer with detailed description.\nTime Complexity: O(n)\nSpace Complexity: O(1)\n\n```\nclass RLEIterator {\n    \n    // Index ptr keeps track of the element that needs to be returned.\n    int diff;\n    int index;\n    int[] enc;\n\n    // Initializing the diff varaible to the first element of the encoding.\n    // Initializing the index ptr to the 1st return element.\n    public RLEIterator(int[] encoding) {\n        enc = encoding;\n        index = 1;\n        diff = encoding[0];\n    }\n    \n    public int next(int n) {\n        \n        // Verify if the index ptr is out of the encoding array.\n        if(index >= enc.length){\n            return -1;\n        }\n        \n        // Subtract the given number from the current diff.\n        // By doing aobve we are exhausting n elements from the array.\n        diff -= n;\n        \n        // If the difference value is >= 0, then the index ptr remains at the same location.\n        // If the difference value is < 0, then we have exhausted all the curr elements.\n        while(diff < 0){\n            // We move the ptr to the next available ele.\n            index += 2;\n            // If the index is out of bounds then we have exhausted all ele from the array.\n            if(index >= enc.length){\n                return -1;\n            }\n            // If the index is in the limits, then update the global diff.\n            diff += enc[index-1];\n        }\n        // Set the new remaining ele count in the array.\n        enc[index-1] = diff;\n        return enc[index];\n    }\n}\n```\n\nPlease upvote if this looks simple & easy to understand/implement. Thanks :)
['Iterator', 'Java']