Design four in a row 00:00:00 Make a prediction You will follow gravity to a landing cell and count a winning line across both sides of the newly placed disc. A new red disc lands between two red neighbours on its left and one on its right. Counting only to the left finds three including itself. Has red actually won? Yes. Count the two contiguous directions on the same axis and include the new disc once. Two plus one plus the newly placed disc gives four. 00:00:30 The tubes in the toy shop Balls drop down clear tubes in a toy shop. A diagonal red pattern is visible on the wall, but you cannot place a ball suspended above an empty part of a tube. Lower balls must support the desired landing cell. The chosen column is the input; gravity computes the row. Only then can you evaluate lines passing through the real landing position. Four in a row in a low-level design round is a referee for a game with gravity: a player names a tube, the ball falls, and the referee says where it landed and whether it made a line. It shows whether somebody thinks about representation: the same rules need four careful methods on a grid, and none on lists that grow. 00:01:15 Check the line through the dropped disc A player chooses column four. Gravity determines the lowest empty row in that column, so a caller cannot supply an arbitrary row. After placing the disc, count matching neighbours from the landing cell on each side of a horizontal, vertical or diagonal axis. Include the new disc exactly once. Two matching discs on one side and one on the other make four together. Testing only one direction would miss this win. Start at the dropped disc and count consecutive matching discs in both directions. Two on one side plus one on the other plus the new disc makes four. A scan from the new disc in only one direction misses the win. Stop at the first gap or opponent disc. 00:01:59 A full column is a rejected move When a player selects a full column, the board must stay unchanged and the same player normally keeps the turn under the chosen rules. Test both properties. Simply flipping the turn after every input lets an invalid move modify game state. Try to drop red into a full column. The board height and current player must remain unchanged. Trying the next empty column should still place a red disc. An implementation that advances the turn before checking capacity can hand a legal turn to the wrong player. Counting every red disc on an axis without requiring contiguity accepts a line with a gap. Add a test where a yellow disc interrupts three reds. Searching only lines through the last move is enough for a legal new win; a full-board scan is simpler for validating imported positions. OpenSpiel models Connect Four as a configurable game. Another environment exposes a move as a column choice and can report which actions are currently legal. The player selects a column, while the board owns gravity and the available height. That separation prevents a caller from placing a disc at an arbitrary floating coordinate. 00:03:12 Try an interview follow-up How do you store the board, and why? I would store a column as an ordered list of discs. Appending a disc naturally enforces gravity, and the current length tells me where it lands. I check the height before appending. If the design also maintains a separate height array, every move must now keep two representations in agreement. A player sends the same move twice because the first response was delayed. Should column three gain two discs? A repeated request with the same move identity should retrieve its original result under an idempotent API. Enforce turn ownership and update the column atomically. Treating the second message as a fresh move could alter a game that was already won. 00:04:03 What to take with you A list for each tube makes floating balls impossible. The caller names a tube, the rack answers with a spot, and the walk starts there: four directions, both ways, outside is empty. Turn and winner follow from the number of drops. The walk is right because a new line must contain the new ball. If a rule moves several balls, read everything. For a computer use bits, a depth limit, an estimate and cut-offs. For two devices give each drop a number.