← Snowflake Interview Insights
I started with the easy stuff, count X's and O's, check that X has either the same count as O or one more.
First, validate the board by counting X's and O's and checking for impossible win configurations. Then determine the game status by checking for wins, draws, or whose turn it is based on the counts.
Pro tip: Clarify the rules upfront: assume X always goes first, and a valid board must have either equal counts or one more X than O. Also, both players cannot win simultaneously.
Count the number of X and O marks on the board to determine if the counts are valid. Valid counts are either X == O or X == O + 1.
Check all rows, columns, and diagonals to see if X or O has three in a row. Record if X wins and/or O wins.
If both X and O win, the board is invalid. If X wins, then X must have one more mark than O. If O wins, then X and O must have equal marks. Otherwise, the board is invalid.
If the board is valid and X wins, return 'X wins'. If O wins, return 'O wins'. If no wins and the board is full, return 'Draw'. Otherwise, return 'X's turn' if counts are equal, else 'O's turn'.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.