Next Optimal Move in Tic Tac Toe
Hard Accuracy: 64.89% Submissions: 111 Points: 8

You are given a middle game situation of the game Tic Tac Toe. It is given that it is player "X's" turn and you need to give to most optimal position for the turn. The situation is given as a 3 x 3 character matrix board. '_' refers to the place is empty. 'o' refers that player O marked it in his turn at some time and 'x' refers that player X marked it in his turn at some time. It is player X's turn. Tell him the most optimal solution.(Assume player O played first). 

Example 1:

Input: board = {{o, _, _}, 
                {_, _, _}, 
                {_, _, _}}
Output: 1 1
Explaination: Placing a 'x' in the (1, 1) 
that is the center of the board is the most 
optimal approach for x.

Your Task:
You do not need to read input or print anything. Your task is to complete the function findBestMove() which takes board as input parameter and returns the best optimal move in a list where the first one is the row index and the second one is the column index.

Expected Time Complexity: O(29)
Expected Auxiliary Space: O(1)

board[i][j] = 'o' / 'x' / '_'  

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Next Optimal Move in Tic Tac Toe

Output Window