Tic-Tac-Toe Board Status
Updated
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.
More Pinecone Online Assessment questions
Similar questions at other companies
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Trapped Characters in a GridAdobe · OAAdobe interview questions
- Count Pieces After Othello MovesHudson River Trading · OAHudson River Trading interview questions
- Robot Navigation Around LasersRoblox · OARoblox interview questions
- Apply a Reversi MoveAmazon · OA
- First Completed Mingo LineEpic · OAEpic interview questions
- Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions
- Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
- Sparse Valid Conv2D From ScratchNVIDIA · OANVIDIA interview questions
- Apply Matrix OperationsCapital One · OACapital One interview questions