Count Circular Alternating Binary Windows
Problem statement
You are given a nonempty binary array bits, treated as circular, and an integer windowLength.
For every start index in the original array, inspect the next windowLength values around the circle. Count how many such windows strictly alternate between 0 and 1.
Function
countCircularAlternatingWindows(bits: int[], windowLength: int) → intExamples
Example 1
bits = [1,0,1,1,0]windowLength = 3return = 3Starts 0, 3, and 4 produce alternating length-three windows.
Example 2
bits = [0,1,0,1]windowLength = 4return = 4Every rotation of the circular array alternates for four values.
Constraints
1 <= bits.length <= 100000bits[i]is 0 or 1.1 <= windowLength <= bits.length