Java : Simple Stack Solution
\nclass RLEIterator {\n    protected Stack<int[]> s;\n    public RLEIterator(int[] encoding) {\n        s = new Stack<>();\n        int lgt = encoding.length;\n
```\nclass RLEIterator {\n    protected Stack<int[]> s;\n    public RLEIterator(int[] encoding) {\n        s = new Stack<>();\n        int lgt = encoding.length;\n        for(int i=lgt-1;i>=0;){\n            int val = encoding[i];\n            int count = encoding[i-1];\n            i=i-2;\n            if(count == 0){\n                continue;\n            }\n            if(!s.isEmpty() && s.peek()[0] == val){\n                int[] top = s.pop();\n                count+=top[1];\n            }\n            s.push(new int[]{val, count});\n        }\n        \n    }\n    \n    public int next(int n) {\n        int ctr = n;\n        int res = -1;\n        while(ctr>0 && !s.isEmpty()){\n            int[] top = s.pop();\n            if(top[1] < ctr){\n                ctr-=top[1];\n            }else{\n                res = top[0];\n                if(top[1]-ctr != 0){\n                    s.push(new int[]{top[0], top[1]-ctr});\n                }\n                break;\n            }\n        }\n        return res;\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 ```
['Stack', 'Java']