board of size m × n, where board[i][j] is a tile color and 0 means an empty cell. Row 0 is the top of the board.
Bring the board to a stable state by repeating rounds:
1. Find every run of three or more equal tiles in a row, horizontally or vertically. All those tiles disappear at the same time (a tile may belong to a horizontal and a vertical run at once).
2. In every column, the remaining tiles fall down until they land on the bottom or on another tile. No new tiles come in from the top; freed cells stay empty.
Once a round has nothing to remove, the board is stable. Return it.board=[[1, 2, 3], [4, 2, 5], [7, 2, 7], [6, 6, 6]] → [[0, 0, 0], [1, 0, 3], [4, 0, 5], [7, 0, 7]]
The column of three 2s and the row of three 6s vanish at the same time. The remaining tiles fall down and no new matches appear.
board=[[6, 2, 3], [6, 4, 4], [1, 1, 1], [6, 5, 7]] → [[0, 0, 0], [0, 2, 3], [0, 4, 4], [0, 5, 7]]
In the first round the three 1s disappear. After the fall, the three 6s in the left column stack up, so they vanish in the second round. Nothing else matches after that.
board=[[1, 2, 1], [2, 1, 2], [1, 2, 1]] → [[1, 2, 1], [2, 1, 2], [1, 2, 1]]
There are no three equal tiles in a row anywhere, so the board is already stable.
board=[[1, 2, 3], [4, 2, 5], [7, 2, 7], [6, 6, 6]]
[[0, 0, 0], [1, 0, 3], [4, 0, 5], [7, 0, 7]]
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.