easy java treemap solution
\nclass RLEIterator {\n     long pos;\n    long currPos =0;\n    int flag =0;\n    TreeMap<Long,Integer> map;\n    public RLEIterator(int[] e) {\n        pos =0
```\nclass RLEIterator {\n     long pos;\n    long currPos =0;\n    int flag =0;\n    TreeMap<Long,Integer> map;\n    public RLEIterator(int[] e) {\n        pos =0;\n        map = new TreeMap<>();\n        //  TreeMap to store the range of encoded values example [0-3]: 8, [3-5]:8 \n        for(int i=0;i<e.length-1;i+=2){\n            if(e[i]==0) continue;\n            pos += e[i];\n            map.put(pos,e[i+1]);\n        }\n        \n    }\n    \n    public int next(int n) {\n        if(flag==1) return -1;\n        if(currPos+n>pos) {\n            flag=1;\n            return -1;\n        }\n        currPos+=n;\n         return map.get(map.ceilingKey(currPos));\n             \n    }\n}\n\n/**\n * Your RLEIterator object will be instantiated and called as such:\n * RLEIterator obj = new RLEIterator(encoding);\n * int param_1 = obj.next(n);\n */\n```
['Tree', 'Java']