Tic-Tac-Toe

This algorithm is often seeked in technical interviews with the question "Design a game of tic tac toe".

You may assume the following rules:

  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 is allowed.
  3. A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.

Variables

Rows: [0,0,0]Cols: [0,0,0]Diagonal: 0Anti diagonal: 0

Winning conditions on move()

Math.abs(rows[row]) == size||Math.abs(cols[col]) == size||Math.abs(diagonal) == size||Math.abs(antiDiagonal) == size

Reset

Leetcode: 348. Design Tic-Tac-Toe