As reported: Glean coding round (2025): implement Connect 4 on a 6 × 7 board. Four in a row — horizontally, vertically or diagonally — wins. Two players alternately insert a token into a column; determine whether a player has won.
Implement ConnectFour:
- The board has 6 rows and 7 columns (columns
0 … 6). Player 1 moves first; players alternate. drop(column)drops the current player's token intocolumn; it falls to the lowest empty cell. Return:- the player number (
1or2) if this move gives that player four or more in a row horizontally, vertically or diagonally; 0if nobody has won yet;-1if the column is full — the move is rejected and the same player moves again.
- the player number (
Example 1
drops: 3 4 3 4 3 4 3 -> [0,0,0,0,0,0,1]
Player 1 stacks four tokens in column 3.
Example 2
drops: 0 1 1 2 2 3 2 3 3 6 3 -> [0,0,0,0,0,0,0,0,0,0,1]
Player 1 completes the diagonal (row 0, col 0) → (row 3, col 3).
Clarifications
- No
dropis called after a win. - A full board with no winner simply ends with
0.
Code runner format: one JSON value: the list of columns dropped in order. Implement the class ConnectFour with drop(column) (Go: Constructor() and Drop); the harness prints the list of return values.