FastPrepTic-Tac-Toe Board Status

Tic-Tac-Toe Board Status

Pinecone logoPinecone● EasyFULLTIMEOA
Learn

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[]) → String

Examples

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 n and contains only X, O, and ..
  • The board is a valid reachable game state with at most one winner.

More Pinecone problems

See Pinecone hiring insights
public String ticTacToeStatus(String[] board) {
    // Write your code here.
}
board["XXX","O.O","..O"]
expected"X"
Checking account…