How Far Have You Gotten in Leet

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Minho Jang

Minho Jang

Backend Developer, Writer, and Lifelong Learner