Count Valid Prefixes
Track the ones and zeros of each prefix; a prefix can be rearranged into alternating bits exactly when those counts differ by at most one.
Track the ones and zeros of each prefix; a prefix can be rearranged into alternating bits exactly when those counts differ by at most one.