Drop and Eliminate Adjacent Pieces
Updated
Problem statement
You are given a rectangular board. It uses 0 for an empty cell and 1 or 2 for a piece color. Rows run from top to bottom. In each column, all pieces start at the bottom with no empty cells between them.
Process the array moves from first to last. Each move is [column, color]. Drop that color into the lowest empty cell of the column. If the column is full, ignore the move.
- Find the group of same-color pieces connected to the new piece through shared sides. Only up, down, left, and right count; diagonals do not.
- If that group has at least two pieces, remove all of them at the same time. Otherwise leave the dropped piece in place.
- After a removal, let the remaining pieces in every column fall downward, keeping their order from top to bottom. That ends the move. Falling pieces do not cause another removal.
Return a new board showing the result after all moves. Do not change either input. Do not remove groups that are not connected to the new piece. This practice variant models drop-and-eliminate transitions; it does not stop on four-in-a-row or return a game winner.
Function
dropAndEliminate(board: int[][], moves: int[][]) → int[][]Examples
Example 1
board = [[0,0,0],[0,0,0],[1,0,2]]moves = [[1,1]]return = [[0,0,0],[0,0,0],[0,0,2]]The new piece touches the bottom-left piece of the same color. Both disappear; the other color stays.
Example 2
board = [[0,0],[2,0],[1,0]]moves = [[1,1]]return = [[0,0],[0,0],[2,0]]The bottom pair of ones disappears. The two above the removed left piece falls to the bottom; this causes no second elimination.
Example 3
board = [[1],[2]]moves = [[0,1]]return = [[1],[2]]The only column is full, so the move is ignored and the board stays unchanged.
Constraints
1 <= rows, columns <= 10; every board row has the same length.- Every initial cell is
0,1, or2, and each column is gravity-compact. 0 <= moves.length <= 200; every move has one valid column ID and color1or2.- The output has the same dimensions and cell encoding as the input board.
More Snowflake Phone Screen questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
- Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026
- Tree Height After Child PromotionPHONE SCREEN · Seen Oct 2026
- Minimum StackPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
- Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
- Minesweeper Board UpdateClay · ONSITE INTERVIEW
- Minesweeper Board UpdateAirbyte · ONSITE INTERVIEW
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot interview questions
- Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
- Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions