FunctionRacerProblemsRace

Noughts and Crosses Verdict

EasyGridsPython, JavaScript, TypeScript, Java, C++

board is a game of noughts and crosses on an n by n board, given as n strings of length n, one per row, top row first. Each character is X, O or . for an empty square. A player has won when their mark fills a whole row, a whole column or one of the two main diagonals (top-left to bottom-right, or top-right to bottom-left). Return "X" or "O" for the winner, "draw" when nobody has won and no square is empty, and "pending" when nobody has won and at least one square is empty. At most one of the two players has a winning line, though that player may have more than one. Do not change board.

Example 1

board ["XO.","OX.","..X"]
returns "X"

X fills the diagonal from the top-left corner to the bottom-right corner.

Example 2

board ["XOX","XOO","OXX"]
returns "draw"

No row, column or diagonal holds a single mark, and every square is taken.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems