You are given an m x n grid board of non-negative integers. A positive value represents a candy type, and 0 represents an empty cell. A match is any horizontal or vertical run of at least three adjacent cells with the same positive value.
Part 1 — find matches. Identify every horizontal and vertical run of length at least 3. Scan start cells in row-major order (top-left to bottom-right). A vertical run is only started from a cell when the cell above it differs or is out of bounds; a horizontal run is only started when the cell to the left differs or is out of bounds. Several reports note a direction-priority requirement: report all vertical matches before horizontal ones.
Part 2 (the main ask) — crush and apply gravity. Return the board after one crush pass: remove every cell that belongs to at least one match (set it to 0), then apply gravity independently in each column so that non-zero values fall downward while preserving their relative order within the column, and empty cells at the top become 0. Important: mark all matched cells first (using a separate marker grid) before zeroing anything, so overlapping and adjacent matches are all detected against the original board.
Follow-up: repeat the crush-and-gravity step until the board is stable (no run of length >= 3 remains), which is the full LeetCode 723 "Candy Crush" variant.
board = [[1, 2, 2, 2], [1, 3, 4, 5], [1, 3, 3, 3], [6, 7, 8, 9]] return = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 3, 4, 5], [6, 7, 8, 9]]
board = [[1, 1, 1], [2, 4, 5], [2, 6, 7]] return = [[0, 0, 0], [2, 4, 5], [2, 6, 7]]
board = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] return = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
1 <= m, n <= 500 <= board[i][j](a positive value is a candy type;0is empty).- A match is a horizontal or vertical run of at least 3 equal positive values.
- Gravity is applied per column, preserving the relative order of surviving values.
- Closest Binary Search Tree Value VariantPHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Find the Closest PalindromePHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest PersonPHONE SCREEN · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026
- Meeting Rooms IIPHONE SCREEN · Seen Jun 2026
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · Seen Jun 2026
public int[][] crushOnce(int[][] board) {
// write your code here
}