Validity of a given Tic-Tac-Toe board configuration - GeeksforGeeks
Validity of a given Tic-Tac-Toe board configuration A Tic-Tac-Toe board is given after some moves are played. Find out if the given board is valid, i.e., is it possible to reach this board position after some moves or not. Note that every arbitrary filled grid of 9 spaces isn't valid e.g. a grid filled with 3 X and 6 O isn't valid situation because each player needs to take alternate turns. Input is given as a 1D array of size 9. Input: board[] = {'X', 'X', 'O', 'O', 'O', 'X', 'X', 'O', 'X'}; Output: Valid Input: board[] = {'O', 'X', 'X', 'O', 'X', 'X', 'O', 'O', 'X'}; Output: Invalid (Both X and O cannot win) Input: board[] = {'O', 'X', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; Output: Valid (Valid board with only two moves played) We strongly recommend you to minimize your browser and try this yourself first. Basically, to find the validity of an input grid, we can think of the conditions when an input grid is invalid. Let no. of "X"s be countX and no. of "O"s be countO.Read full article from Validity of a given Tic-Tac-Toe board configuration - GeeksforGeeks
No comments:
Post a Comment