Search
⌘K

Leetcode 3101. Count Alternating Subarrays

Count the number of contiguous subarrays in a binary array where no two adjacent elements are equal (i.e., the subarray alternates). With n up to 1e5, this is solved by scanning for maximal alternating runs and summing how many subarrays each run contributes (linear time).


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.