FastPrepFastPrep
Problem Brief

Balloon Color Pairs

FULLTIMEOA

You are given an integer length representing the length of a balloon queue (indexed from 0 to length - 1) and an array queries.

Initially, the balloon queue is empty (all positions are uncolored or considered empty).

Each query[i] = (index, color) means you color the balloon at position index with the given color.

After processing each query, you need to count the number of adjacent pairs of balloons that have the same color and record that number.

At the end, you should return an array containing the count after each query — the length of the result array is the same as the number of queries.

1Example 1

Input
length = 5, queries = [[0, 1], [1, 1], [2, 1], [1, 3]]
Output
[0, 1, 2, 0]
Explanation

Initial state: _ _ _ _ _ (empty)

Process each query:

  1. (0, 1): 1 _ _ _ _ → 0 adjacent same-color pairs
  2. (1, 1): 1 1 _ _ _ → 1 pair (positions 0 and 1)
  3. (2, 1): 1 1 1 _ _ → 2 pairs (0-1 and 1-2)
  4. (1, 3): 1 3 1 _ _ → 0 pairs

Final Output: [0, 1, 2, 0]

public int[] countColorPairs(int length, int[][] queries) {
  // write your code here
}
Input

length

5

queries

[[0, 1], [1, 1], [2, 1], [1, 3]]

Output

[0, 1, 2, 0]

Sign in to submit your solution.