Coordinate Removals with Column Gravity
Updated
Problem statement
matrix contains distinct positive values; zero represents empty. Process zero-based [row,column] coordinates in order against the evolving matrix.
If the addressed cell is nonzero, remove it, shift every value above it down by one in that column, and set the top cell to zero. If it is already zero, skip it. Return the final matrix.
Function
removeCellsWithGravity(matrix: int[][], coordinates: int[][]) → int[][]Examples
Example 1
matrix = [[1,2],[3,4]]coordinates = [[1,0]]return = [[0,2],[1,4]]Moved or new
The value above falls into the removed bottom cell.
Example 2
matrix = [[1],[2],[3]]coordinates = [[0,0]]return = [[0],[2],[3]]Moved or new
Removing the top simply replaces it with zero.
Constraints
1 <= rows, columns <= 5000 <= coordinates.length <= 100000- Every coordinate is in bounds.
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
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
- Count Case-Insensitive Key ChangesOA · Seen Sep 2024
Similar questions at other companies
- Rotate Matrix Regions Around the DiagonalsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Rotate Matrix Regions Around the DiagonalsHudson River Trading · OAHudson River Trading interview questions
- Robot Navigation Around LasersRoblox · OARoblox interview questions
- Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
- Apply a Reversi MoveAmazon · OA
- Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
- Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
- First Completed Mingo LineEpic · OAEpic interview questions
- Sort Every Matrix Border LayerCapital One · OACapital One interview questions
- Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions