FastPrepRemove Equal Components and Apply Gravity
Problems/Remove Equal Components and Apply Gravity

Remove Equal Components and Apply Gravity

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report preserves edge-connected equal cells, simultaneous removal to zero, and per-column gravity. The example supports removing components with three visible members despite conflicting threshold wording; this version uses at least three and one round, for an approximate 88% source match.

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]]
grid
012011112032456
→
return
012000012032456
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]]
grid
01021123224
→
return
01001103204
Moved or new

A vertical three-cell component is removed.

Constraints

  • 1 <= rows, columns <= 200
  • 0 <= 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[][] removeComponents(int[][] grid) {
        // Write your code here.
    }

}
Checking account…