I have explained logic through comments. I am getting TLE. I have used kind of a brute force solution. How can i improve it to avoid TLE?
More efficient solution needed for Funky Chess Board
wow thanks! I had not thought that you could modify the original matrix. I was keeping track of previous moves by storing them in a vector and then searching through them. That probably caused TLE.
