RLE Iterator

We compress a sequence with run-length encoding encoding = [cnt0, val0, cnt1, val1, ...] where each pair cnt, val means val appears cnt times consecutively. encoding has even length and may contain zero counts. The expanded sequence is the concatenation of those runs.

Implement an iterator over the expanded sequence:

  • RLEIterator(encoding) constructs the iterator from the run-length array.
  • next(n) exhausts the next n elements and returns the value of the last exhausted element, or -1 if the iterator is exhausted before consuming n elements.
  • hasNext() returns true if at least one element remains, otherwise false.

Operations are relayed through a deterministic functional dispatch solve(operations, args) that returns an array of results where the constructor produces null, next produces a number (-1 on exhaustion), and hasNext produces a boolean.

Examples
Input: [["RLEIterator","next","next","next","next","hasNext"],[[[3,8,0,9,2,5]],[2],[1],[1],[2],[]]]
Output: [null,8,8,5,-1,false]
Hints

RLE Iterator

We compress a sequence with run-length encoding `encoding = [cnt0, val0, cnt1, val1, ...]` where each pair `cnt, val` means `val` appears `cnt` times consecutively. `encoding` has even length and may contain zero counts. The expanded sequence is the concatenation of those runs.