Java TreeMap Solution
Java\nclass RLEIterator {\n    \n    long pos = -1;\n    TreeMap<Long, Integer> map = new TreeMap<>();\n\n    public RLEIterator(int[] encoding) {\n        long
```Java\nclass RLEIterator {\n    \n    long pos = -1;\n    TreeMap<Long, Integer> map = new TreeMap<>();\n\n    public RLEIterator(int[] encoding) {\n        long curr = 0;\n        for(int i=0; i < encoding.length; i+=2){\n            int cnt = encoding[i];\n            int num = encoding[i+1];\n            \n            if(cnt <= 0) continue;\n            \n            curr += cnt;\n            map.put(curr, num);\n        }\n    }\n    \n    public int next(int n) {\n        pos += n;\n        Long key = map.higherKey(pos);\n        return key == null ? -1 : map.get(key);\n    }\n}\n```
['Java']