Bricks Left After Hits Problem
Bricks Left After Hits Problem — ExecCode Hard DSA Practice
Solve the Bricks Left After Hits problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Bricks (1) stick if they are connected (4-dir) to the top row through other bricks. Hits erase bricks in order. After each hit, some bricks may fall. Return how many bricks fall because of that hit (the erased brick itself does not count). Return an array ans where ans[i] is the number of extra bricks that fall after hit i. You are given: grid — 0/1 matrix hits — list of [row, col] erasures Return integer array parallel to hits. A brick on the top row never falls unless it is the one hit; hitting it may drop a hanging cluster below.
Examples
Input {'grid': [[1, 0, 0, 0], [1, 1, 1, 0]], 'hits': [[1, 0]]}; Output [2]. Input {'grid': [[1, 0, 0, 0], [1, 1, 0, 0]], 'hits': [[1, 1], [1, 0]]}; Output [0, 0]. Input {'grid': [[1], [1], [1]], 'hits': [[0, 0]]}; Output [2]
Constraints
Hitting an empty cell causes 0 falls Stability is connectivity to the top row
Practice Bricks Left After Hits free on ExecCode. Browse DSA problems, topic map, and placement guides.