Find the path traversed by a KNIGHT to reach the destination from source in a 8x8 chess broad...
**you will be given the starting position and ending position
Solution:
From any position, a knight can go in 4 different directions. Thus, we do a BFS (using a queue), keeping a set of visited positions. Once we get to the target point, we're done.
Complexity:
time - O(n)Links and credits:
space - O(n)
http://www.careercup.com/question?id=22345665
No comments:
Post a Comment