FastPrepCount Alternating Tile Groups
Problem · Array

Count Alternating Tile Groups

Learn this problem
EasyCapital One logoCapital OneNEW GRADINTERNOA

Problem 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) → int

Examples

Example 1

tileColors = [0,1,0,1,1]size = 3return = 3

The 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 tileColors is either 0 or 1.
  • 1 ≤ size ≤ tileColors.length

Source note: Additional source evidence from a September 5, 2026 Capital One CodeSignal online assessment report.

More Capital One problems

drafts saved locally
public int solution(int[] tileColors, int size) {
  // Write your code here
}
tileColors[0,1,0,1,1]
size3
expected3
checking account