Stabilize a Board by Simultaneous Matches

Quick Overview

Stabilize a Board by Simultaneous Matches. On a rectangular board, positive integers identify candy types and zero denotes an empty cell.

Stabilize a Board by Simultaneous Matches

Company: Roblox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem On a rectangular board, positive integers identify candy types and zero denotes an empty cell. Simultaneously remove every horizontal or vertical run of at least three identical nonzero candies. Then let remaining candies fall within each column, preserving order and adding nothing at the top. Repeat removal and gravity until no run remains, and return that stable board. ```cpp class Solution { public: vector<vector<int>> candyCrush(vector<vector<int>>& board); }; ``` ### Examples **Example 1:** ```text board = [[1,1,1],[2,3,4],[5,6,7]] Output: [[0,0,0],[2,3,4],[5,6,7]] Explanation: Only the first row is removed; the other two rows are already at the bottom. ``` **Example 2:** ```text board = [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,2,3],[4,5,6],[7,8,9]] Explanation: No three equal neighbors occur. ``` ### Constraints - The input is an m-by-n rectangular board with 3 <= m,n <= 50. - Initially every cell contains an integer from 1 to 2000; eliminated cells become zero. ### Contract considerations Keep simultaneous marking, gravity, repeated cascades and the original candyCrush callable. ```hint Read the boundary condition Why must detection finish before any matched cell is cleared? ``` ### Boundary reminders Keep simultaneous marking, gravity, repeated cascades and the original candyCrush callable.

Overview: Stabilize a Board by Simultaneous Matches. On a rectangular board, positive integers identify candy types and zero denotes an empty cell.

Roblox logo
Roblox
Sep 7, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

On a rectangular board, positive integers identify candy types and zero denotes an empty cell. Simultaneously remove every horizontal or vertical run of at least three identical nonzero candies. Then let remaining candies fall within each column, preserving order and adding nothing at the top. Repeat removal and gravity until no run remains, and return that stable board.

class Solution {
public:
    vector<vector<int>> candyCrush(vector<vector<int>>& board);
};

Examples

Example 1:

board = [[1,1,1],[2,3,4],[5,6,7]]
Output: [[0,0,0],[2,3,4],[5,6,7]]
Explanation: Only the first row is removed; the other two rows are already at the bottom.

Example 2:

board = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[1,2,3],[4,5,6],[7,8,9]]
Explanation: No three equal neighbors occur.

Constraints

  • The input is an m-by-n rectangular board with 3 <= m,n <= 50.
  • Initially every cell contains an integer from 1 to 2000; eliminated cells become zero.

Contract considerations

Keep simultaneous marking, gravity, repeated cascades and the original candyCrush callable.

Boundary reminders

Keep simultaneous marking, gravity, repeated cascades and the original candyCrush callable.