Skip to content

Practice Bricks Falling When Hit

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#803
LeetCode Problem

Bricks Falling When Hit

Problem Statement

grid uses 1 for a brick and 0 for empty space. A brick is stable when it lies in the top row or connects to that row through horizontally or vertically adjacent bricks. Apply hits in order. Remove the hit brick if present, then remove other bricks that lose stability; fallen bricks disappear rather than landing below. For each hit, return the number of other bricks that fall, excluding the directly removed brick. Hitting an empty cell drops none.

Source: Bricks Falling When Hit on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,0,0,0],[1,1,1,0]], hits = [[1,0]]
Output
[2]

# Example 2

Input
grid = [[1,0,0,0],[1,1,0,0]], hits = [[1,1],[1,0]]
Output
[0,0]

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 200
grid[i][j] is 0 or 1.
1 <= hits.length <= 4 * 10^4
hits[i].length == 2
0 <= xi <= m - 1
0 <= yi <= n - 1
All (xi, yi) are unique.

Related LeetCode Problems

Practice more problems similar to Bricks Falling When Hit.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.