My try:
we keep an aggregation on consecutive 1
or 0
.
meaning 111000111 is <1,0> <3,1> <3,0> <3,1>
I can represent this with the following DS:
List of Node { digit : bool, counter: long}
1) if the first bulk is of 1's. it turns to bulk of 0`s and turn the very next 0 to 1.
we now check if we can aggregate bulks of 1's.
2) if the first bulk is of 0's, we make the first digit 1. and see if we can aggregate 1's.
example A:
meaning 111000111 is <1,0> <3,1> <3,0> <3,1>
reading: three 1
digits, three 0
digits, three 1
digits, one 0
digits
increment()
<1,0> <3,1> <2,0> <1,1> <3,0>
example B:
<1,0> <3,1> <1,0> <3,1>
increment()
<1,0> <3,1> <1,1> <3,0>
aggregation:
<1,0> <4,1> <3,0>
There will always be const number of changes (up to the right most 0 digit)
and turnning bulk of 1
s is just toggeling the boolean member. which is constant