Connect Four Winner
Reported by candidates from Airbnb's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Airbnb OA from July 2025 asks you to simulate Connect Four and name the winner. It looks like a graph problem, but it's really careful board simulation. Most people lose points on one thing: scanning the whole board after every move, or counting only one direction from the last disc. You've got a 6 by 7 grid, up to 42 moves, and a clean spec. If you blank under the clock, StealthCoder runs invisibly on your screen as a safety net, but this one is very doable if you know the shape.
The problem
Simulate a standard Connect Four game on a board with 6 rows and 7 columns. The integer array moves lists the chosen column for each move in chronological order. Player 1 moves first, and the players alternate. A disc falls into the lowest empty cell in its chosen column. Return the player number of the first player who forms four of their discs in a contiguous horizontal, vertical, or diagonal line. Return 0 if the sequence ends without a winner. Every supplied move is legal, and the sequence contains no move after a player has won. Function connectFourWinner(moves: int[]) → int Examples Example 1 moves = [3,2,3,2,3,2,3] return = 1 Player 1 places four discs in column 3, so the final move completes a vertical line. Example 2 moves = [0,0,1,1,2,2,3] return = 1 Player 1 occupies the bottom cells of columns 0 through 3 and wins horizontally. Example 3 moves = [0,1,2,3] return = 0 Neither player has four connected discs when the move sequence ends. Constraints 1 <= moves.length <= 42. Every value in moves is an integer from 0 through 6. Each move selects a column that is not full. Player 1 moves first, then the players alternate. The sequence stops at the first winning move or before any player wins.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to check only the disc you just placed. Keep a column height array. For each move, drop the disc at row heights[col], set the cell to the current player, then test four axes: horizontal, vertical, and both diagonals. For each axis, count matching discs in the positive direction, count in the negative direction, add one for the new disc, and check for 4 or more. The classic pitfall is counting only one direction, which misses a disc placed in the middle of a line. Another is forgetting that players alternate by move index, so player is 1 if i is even, else 2. Return the player on the first win, otherwise 0. It's O(n) with a tiny constant. If your direction loop gets messy during the live OA, StealthCoder can hand you the clean version.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Connect Four Winner cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as find winner on a tic tac toe game. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Airbnb's OA.
Airbnb reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Connect Four Winner FAQ
What's the trick to Connect Four Winner?+
Only check around the last placed disc. For four axes, count same-colored discs in both directions from that cell, add one, and see if the total reaches 4. Scanning the full board each move works at this size but is slower and easier to get wrong.
Is this really a graph problem?+
Not in practice. The grid is a graph in theory, but you don't need DFS or BFS. Direction vectors on a matrix and a simple simulation are enough. Treating it as graph traversal just adds code and bugs.
What's the most common mistake?+
Counting in only one direction along an axis. A winning disc can land in the middle of a line, so you need to count both ways and sum. Also watch out-of-bounds checks on the 6 by 7 grid, and don't forget the player alternates by move index.
How do I track where a disc lands?+
Keep an array of seven column heights, all starting at zero. A move in column c lands at row heights[c], then you increment it. The problem guarantees every move is legal, so you don't need to handle full columns.
How do I prepare for this in 48 hours?+
Write it once from scratch with a directions list: (0,1), (1,0), (1,1), (1,-1). Test it against the three examples, especially the vertical and horizontal wins. Then practice a few other grid simulation problems so the bounds checking feels automatic.