FastPrepCandy Crush Grid Matching and Gravity
Problems/Candy Crush Grid Matching and Gravity

Candy Crush Grid Matching and Gravity

Roblox logoRoblox● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The October 16 author-written report (thread 1193392) specifies horizontal matches before vertical matches, each match as value and maximal length, then simultaneous clearing and one stable gravity pass. Its concrete grid and both intermediate/final grids are retained. The part selector and int[][] adapter, numeric bounds and zero-cell support are practice choices; zero support and the optional repeat-until-stable extension preserve compatibility with the historical practice scope. Earlier source URLs remain in the canonical provenance; their unavailable bodies are not used to assert a conflicting direction order.

Given a rectangular grid board, a positive integer is a candy type and 0 is empty. A match is a maximal horizontal or vertical run of at least three equal positive values. Detect every match against the original grid, including both runs when horizontal and vertical matches cross.

Implement match3Round(board, part) with two separately observable results:

  1. part = 1: return one row [value, length] for each match. List all horizontal runs first, ordered by row and then starting column. Next list all vertical runs, ordered by column and then starting row. A run of length four produces one row, not two overlapping triples. If there are no matches, return an empty list.
  2. part = 2: mark the union of all matched cells before changing the board, clear those cells to zero, then compact each column downward. Keep the relative order of every surviving positive value and fill the remaining top cells with zero. Return the resulting grid after exactly one simultaneous clear-and-gravity round.

The two parts read the same original input independently. A match created by gravity is not cleared again during part 2.

For the source example [[1,2,3,4],[7,7,7,7],[5,2,7,1],[6,2,7,3]], the horizontal four sevens precede the vertical three sevens. After clearing, the grid is [[1,2,3,4],[0,0,0,0],[5,2,0,1],[6,2,0,3]]; applying gravity gives the part-2 example below.

Optional, ungraded practice extension: repeat complete rounds until stable. This extension is not part of either return contract.

Function

match3Round(board: int[][], part: int) → int[][]

Examples

Example 1

board = [[1,2,3,4],[7,7,7,7],[5,2,7,1],[6,2,7,3]]part = 1return = [[7,4],[7,3]]

Report the horizontal run of four sevens before the vertical run of three. The shared cell belongs to both runs.

Example 2

board = [[1,2,3,4],[7,7,7,7],[5,2,7,1],[6,2,7,3]]part = 2return = [[0,0,0,0],[1,2,0,4],[5,2,0,1],[6,2,3,3]]

Remove both runs simultaneously, then drop survivors. The new vertical run of twos is retained because this is one round.

Example 3

board = [[1,2],[3,4]]part = 1return = []

Neither direction contains a run of length at least three.

Constraints

  • 1 <= board.length <= 50.
  • 1 <= board[i].length <= 50; all rows have the same length.
  • 0 <= board[i][j] <= 2147483647.
  • 1 <= part <= 2.
  • Matches use only positive values. Zero interrupts a run and represents an empty cell.

More Roblox problems

  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Nov 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public int[][] match3Round(int[][] board, int part) {
        // Write your code here.
    }
}
Checking account…