Available question text
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).
Related questions
Continue with questions that share topics or the same question type.
- Count Bowl Subarrays
Coding
- Count Complete Subarrays in an Array
Coding
- Count Non-Decreasing Subarrays After K Operations
Coding
- Count Number of Nice Subarrays
Coding · Array · Hash Table · Math
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 3101. Count Alternating Subarrays
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source