Search
⌘K

Leetcode 2222. Number of Ways to Select Buildings

Count the number of index triples i<j<k in a binary string that form an alternating pattern "010" or "101" (so no two consecutive selected buildings have the same type). This reduces to summing, for each middle index, the product of opposite-bit counts on its left and right (can be done with prefix/suffix counts in O(n)).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.