beads lists their colours around the ring: 0 is white, 1 is black. The last bead touches the first one.
Call three consecutive beads a **zigzag** when the middle one differs in colour from both of its neighbours (for example white–black–white).
Return how many zigzags the ring contains. Triples that differ in at least one bead count separately.beads=[0, 1, 0, 1] → 4
Colours alternate all the way round, so each of the 4 beads is the middle of a pattern.
beads=[1, 0, 1, 1, 0] → 3
The triples centred at indices 1 and 4 work (index 4 neighbours indices 3 and 0). The answer is 2.
beads=[0, 0, 0] → 0
All beads share a colour, so there are no patterns.
beads=[0, 1, 0, 1]
4
Run checks the first 3 tests in your browser. Submit checks all 134 tests on the server, hidden ones included.