Design Tic-Tac-Toe

Assume the following rules are for the tic-tac-toe game on an n x n board between two players:

Design Tic-Tac-Toe

Assume the following rules are for the tic-tac-toe game on an n x n board between two players:

  1. A move is guaranteed to be valid and is placed on an empty block.
  2. Once a winning condition is reached, no more moves are allowed.
  3. A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.

Implement the TicTacToe class:

  • TicTacToe(int n) Initializes the object the size of the board n.
  • int move(int row, int col, int player) Indicates that player with id player plays at the cell (row, col)of the board. The move is guaranteed to be a valid move.

Follow up:
Could you do better than O(n2) per move() operation?

Constraints:

  • 2 <= n <= 100
  • player is 1 or 2.
  • 1 <= row, col <= n
  • (row, col) are unique for each different call to move.
  • At most n2 calls will be made to move.

Practise: https://leetcode.com/problems/design-tic-tac-toe/

Solution