Given an integer M, an 8 * 8 chessboard and the king is placed on one of the square of the chessboard. Let the coordinate of the king be (R, C).
Note that the king can move to a square whose coordinate is (R1, C1) if and only if below condition is satisfied.
The task is to count the number of position where the king can reach (excluding the initial position) from the given square in exactly M moves.
Input: row = 1, column = 3, moves = 1
Output: Total number of position where king can reached = 5
Input: row = 2, column = 5, moves = 2
Output: Total number of position where king can reached = 19
Approach: Calculate the coordinates of the top left square that can be visited by the king (a, b) and the coordinates of the bottom right square (c, d) of the chessboard that the king can visit. Then the total number of cells that the king can visit will be (c – a + 1) * (d – b + 1) – 1.
Below is the implementation of the above approach:
- Total position where king can reach on a chessboard in exactly M moves | Set 2
- Minimum number of moves required to reach the destination by the king in a chess board
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Count positions in a chessboard that can be visited by the Queen which are not visited by the King
- Number of blocks in a chessboard a knight can move to in exactly k moves
- Check if any King is unsafe on the Chessboard or not
- Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard
- Find minimum moves to reach target on an infinite line
- Minimum time to reach a point with +t and -t moves at time t
- Minimum number of moves to reach N starting from (1, 1)
- Expected number of moves to reach the end of a board | Dynamic programming
- Expected number of moves to reach the end of a board | Matrix Exponentiation
- Minimum moves to reach target on a infinite line | Set 2
- Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls
- Maximum bishops that can be placed on N*N chessboard
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Check if a Queen can attack a given cell on chessboard
- Maximum non-attacking Knights that can be placed on an N*M Chessboard
- Maximum non-attacking Rooks that can be placed on an N*N Chessboard
- Minimum total cost incurred to reach the last station
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.