Leetcode Problem 803. Bricks Falling When Hit
803. Bricks Falling When Hit
AI Mock Interview
Leetcode Solutions
Reverse Time and Union-Find
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Create a copy of the grid after all hits have been applied, marking the hit bricks as absent.
Initialize a DSU structure and connect all bricks that are not hit and are stable.
Connect the top row bricks to a virtual 'roof' node in the DSU.
Iterate through the hits in reverse order, adding back each brick if it was originally there.
For each added brick, connect it to its stable neighbors and update the DSU.
If adding the brick connects new bricks to the roof, count the number of bricks that became stable and add it to the result.
Reverse the result array to match the original order of hits.
Return the result array.
Depth-First Search (DFS) Post-Processing
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...