Connect Four from the Last Move
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Snowflake OA reported in September 2026 hands you a Connect Four board and one move, then asks if that move makes four in a row. The hint says graph, but the structure that matters is just the 2D grid and four direction pairs. No BFS, no visited set. You walk outward from [row, col] and count. It looks like a game problem and it's really a bounds-checking problem. If your head goes blank under the timer, StealthCoder runs invisibly during the live assessment as a safety net, so one frozen minute doesn't sink the whole attempt.
The problem
A rectangular Connect Four board contains 0 for empty cells and 1 or 2 for player pieces. The piece at [row, col] is the move that was just placed by player. Return whether that move belongs to a horizontal, vertical, or diagonal contiguous run of at least four player pieces. You only need to determine whether the supplied move completes a run; do not validate gravity or earlier game history. Function didPlayerConnectFour(board: int[][], row: int, col: int, player: int) → boolean Examples Example 1 board = [[0,0,0,0],[1,1,1,1],[0,0,0,0]] row = 1 col = 3 player = 1 return = true The supplied move completes a horizontal run of four. Example 2 board = [[2,0,0,0],[0,2,0,0],[0,0,2,0],[0,0,0,2]] row = 2 col = 2 player = 2 return = true The move lies on a four-piece diagonal. Example 3 board = [[1,1,1,0]] row = 0 col = 2 player = 1 return = false Three contiguous pieces are not enough. Constraints 1 <= board.length, board[i].length <= 200. All rows have equal length and every cell is 0, 1, or 2. row and col identify a valid cell and player is 1 or 2.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: don't scan the whole board. Start at the given cell and check four axes: horizontal (0,1), vertical (1,0), diagonal (1,1), and anti-diagonal (1,-1). For each axis, count contiguous matching pieces in the positive direction, then the negative direction, add 1 for the move itself, and return true if any total hits 4 or more. That's O(1) work per axis since you can stop at 4, and it's O(1) space. Pitfalls: forgetting the negative direction, so a move in the middle of a run fails. Also off-by-one on bounds, and counting the starting cell twice. The example with [1,1,1,0] returning false is the sanity check for exactly that. Don't validate gravity, the problem says to skip it. If the loop logic slips while you're timed, StealthCoder is the hedge in the live OA, reading the problem and giving you the direction-pair solution.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Connect Four from the Last Move 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Connect Four from the Last Move FAQ
How hard is the Snowflake Connect Four OA question really?+
Easy to medium. There's no clever algorithm. The difficulty is writing clean direction logic without bounds bugs. If you've done grid problems before, it's a ten-minute solution. Most failures come from missing the opposite direction, not from the idea itself.
What's the trick to solving it fast?+
Only check from the placed piece. Define four direction pairs, like (0,1), (1,0), (1,1), (1,-1). For each, count matches forward and backward, add one, and compare to four. Loop over the directions so you write the counting code once.
Do I need BFS or DFS since it's tagged graph?+
No. The grid is technically a graph, but you only walk in straight lines from one cell. A simple while loop per direction does it. Flood fill would count non-straight shapes, which is wrong for this problem.
What edge cases should I test?+
Test a move at the end of a run, one in the middle of a run, a run of exactly three, and a 1x1 board. Also test corners and the anti-diagonal so bounds checks get exercised. Example 3, with three in a row returning false, is a good one.
How do I prepare in 48 hours for this kind of grid problem?+
Write this one from scratch twice with a directions array. Then do two or three other grid walks like word search or counting islands. Focus on bounds checks and clean loops. Don't chase new topics the night before.