Say I have an arbitrary RLE Sequence. (For those who don't know, RLE compresses an array like [4 4 4 4 4 6 6 1 1] into [5 4 2 6 2 1]. First comes the number of a particular integer in a run, then the number itself.)

How can I determine an algorithm to set a value at a given index without decompressing the whole thing? For example, if you do set(0,1) the RLE would become [1 1 4 4 2 6 2 1]. (In set, the first value is the index, the second is the value)

I'm trying to find an efficient way to do this, right now I can just think of methods that have WAY too many if statements to be considered clean.

Thanks!