Skip to content

Practice Alternating Groups I

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3206
LeetCode Problem

Alternating Groups I

Problem Statement

Given the circular array colors, where 0 denotes a red tile and 1 a blue tile, count groups of three consecutive tiles whose middle tile has a different color from both neighboring tiles. Groups may wrap from the end of the array to its beginning.

Source: Alternating Groups I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
colors = [1,1,1]
Output
0

# Example 2

Input
colors = [0,1,0,0,1]
Output
3

Constraints

3 <= colors.length <= 100
0 <= colors[i] <= 1

Related LeetCode Problems

Practice more problems similar to Alternating Groups I.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.