Tic-Tac-Toe Game Over
Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The ByteDance OA reported in September 2026 hands you a tic-tac-toe board and asks one thing: is the game over? The whole solution hinges on the data structure you pick, and it's just a handful of counters. No fancy trick. Scan the n x n grid once, track whether any row, column, or diagonal is filled by a single player, and check if any '.' remains. It's a simulation problem dressed up as a game. The risk isn't difficulty, it's sloppy edge cases on n=1 and full boards. If you blank on the OA itself, StealthCoder runs invisibly as a safety net and gives you the solution in real time.
The problem
You are given an n × n tic-tac-toe board encoded as n strings. Cells contain 'X', 'O', or '.' for empty. Return true if the game is over: either one player fills an entire row, column, main diagonal, or anti-diagonal, or the board is full and has no winner. Otherwise return false. Function gameOver(board: String[]) → boolean Examples Example 1 board = ["XXX","O.O","..O"] return = true X fills the first row. Example 2 board = ["XO","OX"] return = true The board is full, so the game ended even without considering another move. Constraints 1 <= n <= 500. Every row has length n and uses only X, O, and..
Reported by candidates. Source: FastPrep
Pattern and pitfall
The data structure is two arrays of size n for row and column counts, plus two diagonal counters. Walk every cell once. For an 'X', add 1 to its row, column, and diagonals if it sits on them. For an 'O', subtract 1. If any counter hits n or -n, someone won, so return true. Track empty cells as you go. After the scan, return true if no '.' remains, else false. That's O(n^2) time and O(n) space. Pitfalls: forgetting the anti-diagonal is r + c == n - 1, checking only rows and columns, and treating n=1 wrong. A single 'X' on a 1x1 board is a win, and so is a single 'O'. Also don't validate whether the board is reachable. The input doesn't ask for that. If the clock is tight or your mind goes blank during the live OA, StealthCoder can hand you the clean counter version so you just type and verify.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Tic-Tac-Toe Game Over 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass ByteDance's OA.
ByteDance reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Tic-Tac-Toe Game Over FAQ
How hard is the ByteDance Tic-Tac-Toe Game Over question really?+
Easy on logic, easy to botch on details. It's a single pass over an n x n grid. Most failures come from missing the anti-diagonal, mishandling n=1, or forgetting the full-board case. If you can write the counters cleanly, you're done in minutes.
What's the trick to solving it in one pass?+
Use counters. Keep one per row, one per column, and two for the diagonals. Add 1 for X and subtract 1 for O. If any counter reaches n or -n, that player filled the line. Also count empty cells so you can detect a full board at the end.
Do I need to check if the board is a valid game state?+
No. The problem only asks whether the game is over: a filled line by one player, or a full board with no winner. Don't add reachability checks like X count versus O count. They aren't in the statement and just add bugs.
What edge cases should I test before submitting?+
Test n=1 with 'X', 'O', and '.'. Test a full board with no winner like ["XO","OX"], which should return true by the diagonal anyway. Test an anti-diagonal win and a board with empty cells and no line, which returns false.
How do I prepare for this in 48 hours?+
Write the counter solution from scratch twice, then test the edge cases by hand. Also skim similar grid-scan problems so the row, column, and diagonal indexing feels automatic. Keep it simple. Don't over-engineer a problem that's a single scan.