Problem · Matrix
Bubble Popping Game
You are given a 2D array grid, where grid[i][j] represents the color of the bubble at position (i, j). You are also given an operations array, which is a sequence of coordinates indicating where to pop bubbles.
Rules:
Examples
01 · Example 1
grid = [[1, 2, 3], [6, 1, 2], [1, 2, 5]] operations = [[1, 1], [1, 2]] return = [[0, 0, 0], [0, 0, 3], [6, 2, 5]]
Step 1: Pop bubble at (1, 1)
- Pops the bubble itself
- Pops diagonally connected bubble (0, 0) because it has the same color 1
[
[0, 0, 3],
[0, 2, 2],
[6, 2, 5]
]
Step 2: Pop bubble at (1, 2)
- Pops the bubble itself
- Pops diagonal (0, 1) because it's 2
- Pops diagonal (2, 1) because it's also 2
[
[0, 0, 0],
[0, 0, 3],
[6, 2, 5]
]
Final Output:
[
[0, 0, 0],
[0, 0, 3],
[6, 2, 5]
]
More Instacart problems
public int[][] popBubbles(int[][] grid, int[][] operations) {
// write your code here
}
grid[[1, 2, 3], [6, 1, 2], [1, 2, 5]]
operations[[1, 1], [1, 2]]
expected[[0, 0, 0], [0, 0, 3], [6, 2, 5]]
sign in to submit