Remove Equal Components and Apply Gravity
Updated
Problem statement
Positive cells of equal value form components through shared edges; zero is empty. In one simultaneous round, remove every component containing at least three cells by setting it to zero.
Then compact each column downward toward larger row indices, preserving the top-to-bottom order of surviving values. Return the resulting matrix.
Function
removeComponents(grid: int[][]) → int[][]Examples
Example 1
grid = [[1,1,1],[2,0,3],[4,5,6]]return = [[0,0,0],[2,0,3],[4,5,6]]Moved or new
The three ones disappear and columns compact downward.
Example 2
grid = [[2,1],[2,3],[2,4]]return = [[0,1],[0,3],[0,4]]Moved or new
A vertical three-cell component is removed.
Constraints
1 <= rows, columns <= 2000 <= grid[r][c] <= 1000000000
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
- Count Islands from Streaming RowsAmazon · ONSITE INTERVIEW
- Rotate Matrix Regions Around the DiagonalsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Shortest Atom Action PathOpenAI · OAOpenAI interview questions
- Rotate Matrix Regions Around the DiagonalsHudson River Trading · OAHudson River Trading interview questions
- Robot Navigation Around LasersRoblox · OARoblox interview questions
- Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
- Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions