Finding final configuration after flipping bits

34 Views Asked by At

You have a thousand bits, all 0s (zeros). We define an operation as flipping all bits between the a-th bit and the b-th bit. What is the fastest way to find the final configuration after a thousand operations?

1

There are 1 best solutions below

2
On

Count all occurrences of the values (a,b). Scan the values occurrences, from least to most where the pattern starts with 0 bits. With the first odd count changes values to 1. At the next odd value change to 0. And so on every odd count changes the value of the string following it.