We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop.
We will do some erasures sequentially. Each time we want to do the erasure at the location (i, j), the brick (if it exists) on that location will disappear, and then some other bricks may drop because of that erasure.
Return an array representing the number of bricks that will drop after each erasure in sequence.
grid = [[1,0,0,0],[1,1,1,0]]
hits = [[1,0]]
If we erase the brick at (1, 0), the brick at (1, 1) and (1, 2) will drop. So we should return 2.
grid = [[1,0,0,0],[1,1,0,0]]
hits = [[1,1],[1,0]]
When we erase the brick at (1, 0), the brick at (1, 1) has already disappeared due to the last move. So each erasure will cause no bricks dropping. Note that the erased brick (1, 0) will not be counted as a dropped brick.
For each day, hit and clear the specified brick.
Find all connected components (CCs) using DFS.
For each CC, if there is no brick that is on the first row that the entire cc will drop. Clear those CCs.