Java || Explained question || Explained steps to solve || O(N)
// The encoding[] array is the encoded version of some array. Every even pos \'i\' (0, 2, 4, 6,...) in this encoded array tells how many elements at encoding[i 
// The encoding[] array is the encoded version of some array. Every even pos \'i\' (0, 2, 4, 6,...) in this encoded array tells how many elements at encoding[i + 1] are there(consecutively) in original array\n// Ex : [8,8,8,5,5] -> [3,8,2,5] -> this means that there are 3 ->8s and 2 -> 5s in original array which we can clearly see\n// Also [8,8,8,5,5] ->[3,8,0,9,2,5] -> 3 -> 8s, 0 -> 9s, 2 -> 5s. There are 0 9s which is also true so this encoded array is also valid\n\n// Do following steps to give next\n// 1. Maintain index (this tells at which index of encoded array are we pointing, even after some exhauting has happened)\n// 2. check if \'n\' <= A[index] -> we are trying to see if the number at position \'n\' int he original array is still there (since we exhaust numbers -> meaning we remove them)\n// For ex -> n = 2, index 0, A[index] = 3\n// This means that we wants to fetch 2nd number from the original element and A[index] = 3 means that there are 3 same elements so we return A[index + 1] (which contains the actual value) and reduce the value of A[index] ny n. So now A[index] = 3 - 2 = 1 (this means that we have exhausted 2 8s, and now only 1 8 is left) -> [8 ,5 , 5]\n// 3. If the n > A[index], this means that we wanted to fetch a number from original array at pos \'n\' but the current index at A, A[index] does not point to that nth position number, so we need to update our index and exhaust all the lements befre that nth element\n\n// TC : O(N)\n// SC : O(1)\n\n```\nclass RLEIterator {\n\n    int[] A;\n    int index;\n    public RLEIterator(int[] encoding) {\n        this.A = encoding;\n        this.index = 0;\n    }\n    \n    public int next(int n) {\n        while(index < A.length) {\n            if(n <= A[index]) { // step 2\n                A[index] -= n;\n                return A[index + 1];\n            } // step 3\n            n = n - A[index];\n            index = index + 2;\n        }\n        return -1;\n    }\n}\n```
[]