How Far Have You Gotten in Leet

Minho Jang
1 min readDec 30, 2020

--

*** This solution came from Keshav613’s explanation.

Question

resource: https://leetcode.com/problems/valid-tic-tac-toe-state/

Explanation

  1. The first player always starts with ‘X’, which means that the number of X must be greater than or equal to the number of O when the game ends.
  2. The game ends when three of the same character fill any row, column, or diagonal. Basically, no more than one sequence must be created when the game ends.
  3. There are two special cases when two sequences could be made in a game. First, when ‘X’ makes two, X must be one more than O. Secondly, when ‘O’ makes two, O must be equal to X.
  4. Every other game could reach the designated board position.

Solution

Review

Didn’t make it to handle the special cases and, as a result, failed over and over again. The original code was kinda brute-force solution, which gets rid of all the impossible cases found, rather than a logical solution. When It could not be possible to find out all the exceptions, try to make a logic first.

--

--

Minho Jang
Minho Jang

Written by Minho Jang

Backend Developer, Writer, and Lifelong Learner

No responses yet