Trains the technique from
LeetCode 723Candy CrushThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A puzzle board is given as board, a rectangle of cells. board[i][j] is the colour code of the piece resting in row i and column j, where row 0 is the top row. A value of 0 means the cell is empty; the starting board has no empty cells.
The board settles by repeating these two steps until a round changes nothing:
Carry the settling out in place on board, changing the given rows rather than building a new rectangle, and return board once no further round changes anything.
Example 1
Column 0 holds three 3s in rows 0 to 2 and column 1 holds three 2s in rows 1 to 3, so those six pieces go. The 4 in column 0 and the 7 in column 1 then drop to the bottom row, and the resulting board has no group of three left.
Example 2
Row 1 holds three 2s across columns 0 to 2, column 1 holds three 2s down rows 0 to 2, and column 3 holds three 4s down rows 0 to 2. The 2 at row 1 column 1 belongs to two of those groups and is removed once. After the survivors drop, no group of three remains.
Example 3
The three 5s in row 2 go first. The three 4s in column 0 then sit on rows 1, 2 and 3, so a second round removes them, and after that round nothing more matches.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def candy_crush(board: list[list[int]]) -> list[list[int]]:public int[][] candyCrush(int[][] board)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.