Reported June 2026
Hebbiamatrix

Detect a Winner on a 3x3 Tic-Tac-Toe Board

Reported by candidates from Hebbia's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Hebbia OA. Under 2s to a working solution.
Founder's read

Hebbia reportedly sent this one in June 2026, and it's a quiet one. Brute force isn't even a question here, because the board is fixed at 3x3 and there are only eight lines to check. Return X, O, or None. If you're expecting a trap, the trap is overthinking it. You've got a short window before the OA, so know the shape cold: scan rows, columns, and two diagonals. And if you blank on the indexing under pressure, StealthCoder runs invisibly during the live assessment and can hand you the clean version.

The problem

Given a completed or partially completed 3 × 3 Tic-Tac-Toe board, return X if X occupies a complete row, column, or diagonal, return O if O does, and otherwise return None.
Each row is a string containing only X, O, and.. The board is reachable from legal alternating play, so it cannot contain simultaneous winners.

Function
ticTacToeWinner(board: String[]) → String

Examples
Example 1
board = ["XXX","O.O","..."]
return = "X"
X fills the first row.
Example 2
board = ["XO.","XO.",".O."]
return = "O"
O fills the middle column.
Example 3
board = ["XO.","OX.","..."]
return = "None"
No row, column, or diagonal is complete.

Constraints
board.length == 3
board[i].length == 3
Every character is X, O, or..
The board has no simultaneous winners.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The input size is the whole story. Three rows, three columns, two diagonals. That's eight fixed lines, so the work is constant time and there's nothing to optimize. The clean approach is to define the eight triples of coordinates, or loop i from 0 to 2 for rows and columns, then check both diagonals separately. For each line, if all three cells match and aren't a dot, return that character. The common pitfall is treating '.' as a winner because three empty cells in a row are equal. Check for the dot first. Another slip is returning the lowercase or Python None object when the spec wants the string "None". The guarantee of no simultaneous winners means you can return on the first hit. If you freeze on the diagonal indices, StealthCoder is the hedge during the live OA, but this one is easy to hand-write.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Detect a Winner on a 3x3 Tic-Tac-Toe Board 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 StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Hebbia's OA.

Hebbia 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.

Detect a Winner on a 3x3 Tic-Tac-Toe Board FAQ

How hard is the Hebbia tic-tac-toe winner question really?+

Easy. It's a fixed 3x3 grid with eight winning lines, so there's no algorithm to discover. The difficulty is only in careless mistakes like counting empty cells as a win or returning the wrong output format. Write it slowly and test the three examples.

What's the trick to detecting the winner?+

There isn't a deep one. Check three rows, three columns, and two diagonals. For each line, confirm all three characters match and aren't '.'. Return the matching character right away. Because simultaneous winners are ruled out, the first complete line you find is the answer.

Do I need to validate that the board is legal?+

No. The problem says the board comes from legal alternating play and has no simultaneous winners. You don't need to count X and O or check turn order. Skipping validation keeps the code short and avoids bugs from extra logic nobody asked for.

What should I return when nobody has won?+

Return the string "None", not a null value. The function signature returns a String, and example 3 shows "None" for a board with no complete line. That includes full boards that end in a draw and partially filled boards with no winner yet.

How do I prepare for this in 48 hours?+

Write it once from scratch with a list of eight coordinate triples, then once with loops. Test an empty-row case like "..." to confirm you don't return a dot. Spend the remaining time on harder grid and hash map problems, since this one is basic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Hebbia.

OA at Hebbia?
Invisible during screen share
Get it