---
# System prepended metadata

title: 0900. RLE Iterator
tags: [Leetcode, Medium]

---

# 0900. RLE Iterator
###### tags: `Leetcode` `Medium`
Link: https://leetcode.com/problems/rle-iterator/
## Code
```java=
class RLEIterator {
    int idx;
    int[] arr;
    public RLEIterator(int[] encoding) {
        idx = 0;
        this.arr = encoding;
    }
    
    public int next(int n) {
        int len = arr.length;
        int ans = 0;
        while(idx<len && n>arr[idx]){
            n = n-arr[idx];
            idx+=2;
        }
        if(idx==len) return -1;
        arr[idx] = arr[idx]-n;
        return arr[idx+1];
    }
}
```