Given four integers sourceX, sourceY, destinationX and destinationY which represent the source and destination coordinates on a chessboard. The task is to find the minimum number of moves required by the king to reach from source to destination.
A king can move to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Print path using L, R, U, D, LU, LD, RU and RD where L, R, U and D represent left, right, up and down repectively.
Input: sourceX = 4, sourceY = 4, destinationX = 3, destinationY = 5
Input: sourceX = 4, sourceY = 4, destinationX = 7, destinationY = 0
Approach: Move in the diagonal direction towards the destination until the king reaches same column or same row as the destination, then move towards the destination in a straight line.
Below is the implementation of the above approach:
4 UL UL UL L
- Total position where king can reach on a chessboard in exactly M moves
- Minimum number of given moves required to make N divisible by 25
- Minimum moves to reach target on a infinite line | Set 2
- Find minimum moves to reach target on an infinite line
- Number of moves required to guess a permutation.
- Minimum time to reach a point with +t and -t moves at time t
- Minimum number of jumps to reach end
- Minimum number of operations required to reduce N to 1
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum number of changes required to make the given array an AP
- Minimum number of mails required to distribute all the questions
- Minimum number of integers required to fill the NxM grid
- Minimum number of bottles required to fill K glasses
- Minimum number of operations required to sum to binary string S
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.