street: '0' is an office, '1' is a café. An inspector wants to pick three buildings, taken in street order, so that their types alternate: no two neighbours within the chosen triple may be of the same type. In other words, only "office, café, office" and "café, office, café" are allowed.
Return the number of ways to pick such a triple. Two ways differ if they pick a different set of buildings.street='10011' → 4
Only "café, office, café" works: building 0, then building 1 or 2, then building 3 or 4, so 2 · 2 = 4 ways. "Office, café, office" is impossible because no office comes after a café.
street='000111' → 0
All the offices come before all the cafés, so no alternating triple exists.
street.length ≤ 10⁵street[i] is '0' or '1'street='10011'
4
Run checks the first 3 tests in your browser. Submit checks all 164 tests on the server, hidden ones included.