Problem 4006 · Medium

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.

Open the interactive visualisation