Find Winner on Tic Tac Toe

Easy

Description

Tic-tac-toe is played on a 3x3 grid by two players A and B who alternately place X and O. Given an array of moves, determine the winner. Return "A", "B", "Draw", or "Pending".

Examples

Input:moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
Output:"A"
Explanation:

A wins diagonally.

Input:moves = [[0,0],[1,1],[0,1],[1,2],[0,2]]
Output:A
Explanation:

A wins with a horizontal line in the top row (positions [0,0], [0,1], [0,2]).

Input:moves = [[0,0],[0,1],[1,0],[1,1],[2,1],[2,2]]
Output:Pending
Explanation:

After 6 moves, no player has achieved three in a row. The game is still ongoing with 3 empty positions remaining.

Constraints

  • 1 ≤ moves.length ≤ 9

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!