FastPrepPop Matching Balloon Neighborhoods

Pop Matching Balloon Neighborhoods

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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 <= 200
  • 0 <= grid[r][c] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[][] popBalloons(int[][] grid) {
    // Write your code here.
}
grid[[0,1,0],[1,1,1],[0,2,0]]
expected[[0,0,0],[0,0,0],[0,2,0]]
Checking account…