Pop Matching Balloon Neighborhoods
Problem statement
Positive integers are balloon colors and zero is empty. Evaluate one simultaneous popping round. A nonzero center triggers when at least two of its orthogonal neighbors have the same color; pop the center and every same-colored orthogonal neighbor of every triggering center.
After all pops, compact surviving balloons toward larger row indices within each column, preserving their order. Return the result.
Function
popBalloons(grid: int[][]) → int[][]Examples
Example 1
grid = [[0,1,0],[1,1,1],[0,2,0]]return = [[0,0,0],[0,0,0],[0,2,0]]The center and its three matching neighbors pop before gravity.
Example 2
grid = [[1,1],[2,3]]return = [[1,1],[2,3]]One matching neighbor is insufficient.
Constraints
1 <= rows, columns <= 2000 <= grid[r][c] <= 1000000000