Balloon Color Pairs
Updated
Problem statement
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.
Function
countColorPairs(length: int, queries: int[][]) → int[]Examples
Example 1
length = 5queries = [[0, 1], [1, 1], [2, 1], [1, 3]]return = [0, 1, 2, 0]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]
More Instacart interview questions
- Find First and Last Position in a Sorted ArrayPHONE SCREEN · Seen Nov 2026
- Squares of a Sorted ArrayPHONE SCREEN · Seen Nov 2026
- Evaluate Formulas with Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Process Shopping Records, Promotions, and Display OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Product Total With the Cheapest PromotionONSITE INTERVIEW · Seen Sep 2026
- Sort Products by Aisle With Frozen Items LastONSITE INTERVIEW · Seen Sep 2026
- Timed Task ManagementONSITE INTERVIEW · Seen Sep 2026
- Worker Management with Promotions and Double-Paid TimeONSITE INTERVIEW · Seen Sep 2026
- 🦉 Collect SticksOA · Seen Mar 2025
- Bubble Popping GameOA · Seen Mar 2025
Similar questions at other companies
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Calculate Portfolio Rebalancing DeltasAkuna Capital · OAAkuna Capital interview questions
- Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
- Get Total RequestsAmazon · OA
- Command Frequency CounterUber · OAUber interview questions
- Cargo Port Ship StopsNutanix · OANutanix interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
- Process Banking OperationsVercel · OA