Clean java code beats 94% O(N) with intuition
\n/**\n\tIntuition: Take a current pointer with starting index. For each of the next call, search for an index which has \n\tpositive run length and return the 
```\n/**\n\tIntuition: Take a current pointer with starting index. For each of the next call, search for an index which has \n\tpositive run length and return the element. Else keep moving forward until a value > n is found. \n\tTime Complexity: O(N) \n\tSpace Complexity: O(constant). \n**/\nclass RLEIterator {\n\n    int[] e;\n    int cur;\n   \n    public RLEIterator(int[] encoding) {\n        e = encoding; \n        cur = 0;\n    }\n    \n    public int next(int n) {\n        // System.out.println(Arrays.toString(e));\n        while(cur < e.length - 1) {\n            if(n > e[cur]) {\n                n = n - e[cur];\n                e[cur] = 0;\n                cur += 2;\n            } else {\n                e[cur] -= n;\n                return e[cur + 1];\n            }\n        }\n        return -1;\n    }\n}\n```\n
[]