Balloon Color Pairs
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
Initial state: _ _ _ _ _ (empty)
Process each query:
- (0, 1): 1 _ _ _ _ → 0 adjacent same-color pairs
- (1, 1): 1 1 _ _ _ → 1 pair (positions 0 and 1)
- (2, 1): 1 1 1 _ _ → 2 pairs (0-1 and 1-2)
- (1, 3): 1 3 1 _ _ → 0 pairs
Final Output: [0, 1, 2, 0]