Noughts and Crosses Verdict
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
X fills the diagonal from the top-left corner to the bottom-right corner.
Example 2
No row, column or diagonal holds a single mark, and every square is taken.
Constraints
1 <= n <= 6len(board[r]) == nfor every row- every character is
X,Oor. - at most one player fills a whole line
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Quarter TurnEasy
- Richest Square BlockEasy
- Ring WalkEasy
- Row and Column SwitchesEasy
- Same Letter RegionEasy
- Stones SettleEasy
- Turns to MatchEasy
- Turtle CommandsEasy