Practice Alternating Groups II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
The entries of colors form a circle, where 0 represents red and 1 represents blue. Count the groups of k consecutive tiles whose neighboring tiles within the group have different colors. Groups may wrap from the end of colors to its beginning. Return the number of these alternating groups.
Source: Alternating Groups II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
colors = [0,1,0,1,0], k = 3
Output
3
# Example 2
Input
colors = [0,1,0,0,1,0,1], k = 6
Output
2
# Example 3
Input
colors = [1,1,0,1], k = 4
Output
0
Constraints
3 <= colors.length <= 10^5
0 <= colors[i] <= 1
3 <= k <= colors.length
Related LeetCode Problems
Practice more problems similar to Alternating Groups II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.