LEARNING JOURNAL

I created this learning journal to practice writting and to help me learn by writting everything down. Source code here

1/30/2024

RLE Iterator

Here is the solution for the RLE iterator problem and I am trying to make sense of it.

The class RLEIterator receives an encoding array and stores the info as a private array of object of the type {num, count}.

In the next function, there is a for loop that goes over _arr, picks out the first item (first block), sees if the block is longer or shorter than n.

If the block is shorter (n > item.count --> n > 0), do nothing, go to the next block.

If the block is longer (n <= item.count --> n <= 0), see how many left from the block (the difference between n and item.count). Because the block is shorter, the current item is inside the block, which is the block's value.

If item.count > 0, add it back to the _arr, otherwise, do nothing.