Super Simple Java Using Stack with Explanation
\nclass RLEIterator {\n    Stack<int[]> stack;\n    public RLEIterator(int[] A) {\n        stack=new Stack<>();\n        int len=A.length; \n        for(int i=l
```\nclass RLEIterator {\n    Stack<int[]> stack;\n    public RLEIterator(int[] A) {\n        stack=new Stack<>();\n        int len=A.length; \n        for(int i=len-1; i>0; i-=2) { // we read from right to left as we use stack and we want index 0 at the top\n            if(A[i-1]>0) stack.push(new int[]{A[i],A[i-1]});  //Records the count of each integer which is i-1 in a stack (except zeros)   \n        }\n    }\n    \n    public int next(int n) {\n        if(stack.isEmpty()) return -1; // if stack is empty means there is nothing left\n        int count=0; int prev=-1;\n        while(!stack.isEmpty() && count<n) { // pop the data from stack till count>=n\n            count+=stack.peek()[1];\n            prev=stack.peek()[0];\n            stack.pop();\n        }\n        if(count<n) return -1; // if count is still smaller, then there is nothing to return\n        if(count==n) return prev; // if count is equals N then there is no reminder to push to the stack\n        count-=n; \n        stack.push(new int[]{prev,count}); // push the remindar count into the stack again\n        return prev;\n    }\n}\n```
[]