I don’t know why I am getting TLE for my solution. I have seen many different solution that had the similar approach and didn’t got TLE.

Problem Link = Tic Tac Toe

My solution = Solution

The basic approach I tried here is to store the turn of every character in a pair of DP and then iterate over all the submatrix of size K*K. Hence finding the minimum of all the possible maximum value in each submatrix and depending on where the minimum value is even or odd giving my final answer.