Detect a Winner on a 3x3 Tic-Tac-Toe Board
Updated
Problem statement
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[]) → StringExamples
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 == 3board[i].length == 3- Every character is
X,O, or.. - The board has no simultaneous winners.
More Hebbia interview questions
Similar questions at other companies
- Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
- Spiral MatrixAthenahealth · ONSITE INTERVIEW
- Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
- Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
- Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
- Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
- Diagonal Matrix IteratorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions