Stabilize a Match-Three Puzzle Board After Cascading Clears

Last updated: November 29, 2026

Quick Overview

In a match-three game board of positive candy IDs (0 means empty), repeatedly crush every horizontal or vertical run of three or more equal candies, let candies above fall into the gaps, and return the board once no runs remain.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


In a match-three game board of positive candy IDs (0 means empty), repeatedly crush every horizontal or vertical run of three or more equal candies, let candies above fall into the gaps, and return the board once no runs remain.

A Meta onsite simulation question for game-adjacent teams, such as Instant Games. The interviewer grades the separation of phases: mark all crushes first, then crush, then apply gravity, then repeat until stable, and cares that overlapping runs are handled.

What the Interviewer Expects
  • Mark all cells to crush before removing any
  • Handle crosses where a cell is in both a row and a column run
  • Apply gravity per column with a write pointer
  • Loop until a full pass finds nothing
  • Analyze the per-round cost and the number of rounds
Key Topics to Cover
Simulation
Grid processing
Two pointers
Fixed point iteration
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Only re-check regions near changed cells instead of the whole board.
  • How would you count the score with combo multipliers?
  • How would you also refill from the top with new random candies?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: m x n grid of non-negative ints (0 = empty). One round: find every cell in a horizontal or vertical run of length >= 3 of the same nonzero value; set all of them to 0 at once; then in each colu...

High-Level Design

Removing runs one at a time would break crosses: an L-shaped or plus-shaped cluster must be crushed together. So each round has two phases.

  1. Mark. Scan each row for triples `g[r][c] == g[r][c+1...

Submit Your Answer
Markdown supported