33. Knight On Chess Board

Given any source point, (C, D) and destination point, (E, F) on a chess board, we need to find whether Knight can move to the destination or not.

Knight's movements on a chess board

The above figure details the movements for a knight ( 8 possibilities ).

If yes, then what would be the minimum number of steps for the knight to move to the said point. If knight can not move from the source point to the destination point, then return -1.

Note: A knight cannot go out of the board.

Input Format:

Output Format:

Constraints:

Example

Solution: (BFS)

Last updated

Was this helpful?