Next Optimal Move in Tic Tac Toe | Practice | GeeksforGeeks

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)
Constraints:
board[i][j] = 'o' / 'x' / '_'  
0
trautmannmartonbence19952 days ago
a1
0
Partha Sarathi Bhunia
This comment was deleted.
0
joya2 years ago
joya
here reference 
0
Soumya Sengupta4 years ago
Soumya Sengupta
Exhaustive recursive solution----------------------------------------1> Start with each free position and calculate the number of combinations for     winning , losing & drawing from this position.
    (While evaluating this, Play O's turn across all available empty spaces too so that all combinations are covered)
2>Compare the results for all the positions and choose the one which gives the maximum benefit.
0
Aniket4 years ago
Aniket
Many of the given expected solutions are wrong. The next optimal move isn't concerned with preventing the opposition from winning the game.
0
Kerem Gürbey4 years ago
Kerem Gürbey
https://uploads.disquscdn.c...
I think there is a problem with the expected solution for this case. If the player does not make move on 2,2, then the next player will, and they will win.
0
th y4 years ago
th y
I'm wondering why the AC rate is more than 20%... Apparently there are many wrong test cases and even the solution suggested in Editorial is problematic in terms of how to take the remaining steps into consideration
0
Pranav Arora5 years ago
Pranav Arora
http://ide.geeksforgeeks.or... plz help!
0
sdarcius5 years ago
sdarcius
Lets consider the following case , _ o _o x _x o _ the most optimal solution is 0 2, which is wining case, but the expected out put is  0 0, could you please resolve it?
0
CNatka5 years ago
CNatka
Incorrect expected answers. Kindly fix the issue.Below is one example -Input:1o x __ o __ _ _
Expected Output : 0 2Correct Output    : 2 2
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.