Tic-Tac-Toe Board Status
Problem statement
Given a valid n x n tic-tac-toe board encoded as an array of strings, return its current status.
Each cell is X, O, or . for empty. A player wins by filling an entire row, column, main diagonal, or anti-diagonal.
- Return
"X"if X has won. - Return
"O"if O has won. - Return
"Tie"if every cell is occupied and neither player won. - Return
"Playing"otherwise.
Function
ticTacToeStatus(board: String[]) → StringExamples
Example 1
board = ["XXX","O.O","..O"]return = "X"X fills the first row.
Example 2
board = ["XO.","OX.","X.."]return = "Playing"No complete line exists and empty cells remain.
Example 3
board = ["XOX","XXO","OXO"]return = "Tie"The board is full and neither player has a complete line.
Constraints
1 <= n <= 500.- Every row has length
nand contains onlyX,O, and.. - The board is a valid reachable game state with at most one winner.