if anyone can give me a proper explanation of how to do
This problem can also be seen as the shortest path in a unweighted graph(Connecting all the edges). Therefore we can use BFS to solve this problem. We try all 8 possible positions where a Knight can reach from its position (Considering only which lie on the chess board). If the reachable position is not already visited and is on the board, we push this state into the queue with distance 1 more than its parent state. Finally, we return distance of target position, when it gets pop out from the queue.
Hope this helps!
yes i did get you, but m facing a problem in calculating the 8 different points to reach portion. lemme read out the source