 <p>I'm assuming the solution you're mentioning in the comment is something like this:</p> <p>Start at the left or right (so index = 0), and scan which bits are set (upto 100 operations). Name that set x. Also set a variable block=0.</p> <p>At index=1, repeat and store to set y. If x XOR y = 0, both are identical sets, so move on to index=2. If it x XOR y = z != 0, then range [block, index) is contiguous. Now set x = y, block = index, and continue.</p> <p>If you have 100 bit-arrays of length 22 each, this takes something on the order of 2200 operations.</p> <p>This is an optimum solution because the operation cannot be reduced further -- at each stage, your range is broken if another set doesn't match your set, so to check if the range is broken you must check all 100 bits.</p>