Problem · Array
Count Alternating Tile Groups
Learn this problemProblem statement
A circular row of red and blue tiles is represented by tileColors. A value of 0 means red and a value of 1 means blue.
Count how many groups of exactly size consecutive tiles have alternating colors, meaning every adjacent pair inside the group has different colors.
The tiles form a circle, so the first and last elements of tileColors are adjacent.
A solution with time complexity no worse than O(tileColors.length^2) fits within the execution limit.
Function
solution(tileColors: int[], size: int) → intExamples
Example 1
tileColors = [0,1,0,1,1]size = 3return = 3The groups beginning at indices 0, 1, and 4 alternate. The other two groups contain adjacent blue tiles, so the result is 3.
Constraints
tileColors.length ≥ 1- Every element of
tileColorsis either0or1. 1 ≤ size ≤ tileColors.length
Source note: Additional source evidence from a September 5, 2026 Capital One CodeSignal online assessment report.