[JAVA] | O(n) time O(1) space | Recursive Approach
\nint index;\nint[] A;\npublic RLEIterator(int[] A) {\n\tthis.A = A;\n\tindex = 0;\n}\n\npublic int next(int n) {\n\tif (index >= A.length) {\n\t\treturn -1;\n\
```\nint index;\nint[] A;\npublic RLEIterator(int[] A) {\n\tthis.A = A;\n\tindex = 0;\n}\n\npublic int next(int n) {\n\tif (index >= A.length) {\n\t\treturn -1;\n\t}\n\n\tif (n <= A[index]) {\n\t\tA[index] -= n;\n\t\treturn A[index + 1];\n\t} else {\n\t\tindex += 2;\n\t\treturn next(n - A[index - 2]);\n\t}\n}\n```
['Recursion', 'Java']