BFS definitely works here, but the more intuitive way for me to think about the problem was to visit each point in the grid in the order in which they are numbered (will require inital grid traversal and adding points to an extra array in the correct order). After that, you can just go point by point and check if moving from the previous point to the current point is a valid move ((diffX==1 AND diffY==2) OR (diffX==2 AND diffY==1)).
@FisherCoder Жыл бұрын
Cool, that's a nice approach as well, thanks for sharing!
@minaamir3056 Жыл бұрын
your explanation helped me to understand this problem because I participated in this contest and I read the description like 20 times and I didn't understand what is the problem at all, the description is very poor and naive, what I understood the knight moving in full chessboard like 8*8 board and the numbers are the positions he moved to and from like he will start from position 0 to 11 to 16, etc. using a chessboard here is nonrelevant at all, he could say that if you start on the [0,0] position and kept moving like a knight in a chessboard you will find the next position incremented by one not saying There is a knight on an n x n chessboard. I don't know if you get me or not but thanks anyway for the explanation, you know once I understood the problem from you I solved it in less than 30 minutes, but back in the contest I couldn't make any progress at all
@FisherCoder Жыл бұрын
I got you, and I'm glad that my video helped in this case, thanks for sharing! Cheers!