Tap here to switch tabs
Problem
Submissions

Problem: Candy Crush

med
30 min
Try to solve the Candy Crush problem.

Statement

Given an m × \times n integer matrix board representing a grid of candies, where each positive integer represents a distinct candy type and 00 represents an empty space, simulate the process of the Candy Crush game according to the following rules:

  1. Identify all groups of 33 or more adjacent candies of the same type aligned horizontally or vertically.

  2. Crush all identified candies simultaneously by changing their values to 00.

  3. Apply gravity so that the remaining candies in each column drop down to fill the empty spaces below them. Any empty spaces left at the top of the columns are filled with 00.

  4. Repeat steps 11 through 33 until no more candies can be crushed.

Return the final state of board after the grid reaches a stable configuration.

Constraints:

  • m ==== board.length

  • n ==== board[i].length

  • 3≤3 \leq m, n ≤50\leq 50

  • 1≤1 \leq board[i][j] ≤2000\leq 2000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Candy Crush

med
30 min
Try to solve the Candy Crush problem.

Statement

Given an m × \times n integer matrix board representing a grid of candies, where each positive integer represents a distinct candy type and 00 represents an empty space, simulate the process of the Candy Crush game according to the following rules:

  1. Identify all groups of 33 or more adjacent candies of the same type aligned horizontally or vertically.

  2. Crush all identified candies simultaneously by changing their values to 00.

  3. Apply gravity so that the remaining candies in each column drop down to fill the empty spaces below them. Any empty spaces left at the top of the columns are filled with 00.

  4. Repeat steps 11 through 33 until no more candies can be crushed.

Return the final state of board after the grid reaches a stable configuration.

Constraints:

  • m ==== board.length

  • n ==== board[i].length

  • 3≤3 \leq m, n ≤50\leq 50

  • 1≤1 \leq board[i][j] ≤2000\leq 2000