Using state variables for the object
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class RLEIterator {
    int currentIdx;
    int[] encoding;
    public RLEIterator(int[] encoding) {
        currentIdx=0;
        this.encoding = encoding;
    }
    
    public int next(int n) {
        while(currentIdx< encoding.length) {
            if(n<=encoding[currentIdx]){
                encoding[currentIdx]-=n;
                return encoding[currentIdx+1];
            }else{
                n-=encoding[currentIdx];
                currentIdx+=2;
            }
        }
        return -1;
    }
}
/**
 * Your RLEIterator object will be instantiated and called as such:
 * RLEIterator obj = new RLEIterator(encoding);
 * int param_1 = obj.next(n);
 */
```
['Java']