Given an integer n, the task is to print the maximum number of bishops that can be placed on a n x n chessboard so that no two bishops attack each other. For example, maximum 2 bishops can be placed safely on 2 x 2 chessboard.
Input: n = 2
We can place two bishop in a row.
Input: n = 5
Approach: A bishop can travel in any of the four diagonals. Therefore we can place bishops if it is not in any diagonal of another bishop. The maximum bishops that can be placed on an n * n chessboard will be 2 * (n – 1).
- Place n bishops in first row
- Place n-2 bishops in last row. We only leave two corners of last row
Below is the implementation of the above approach:
Below is the implementation for bigger values of n:
- Check if the given chessboard is valid or not
- Probability of Knight to remain in the chessboard
- Check if a Queen can attack a given cell on chessboard
- Total position where king can reach on a chessboard in exactly M moves
- Number of blocks in a chessboard a knight can move to in exactly k moves
- Total position where king can reach on a chessboard in exactly M moves | Set 2
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Chessboard Pawn-Pawn game
- Maximum XOR value in matrix
- Find a sub matrix with maximum XOR
- Maximum sum of elements from each row in the matrix
- Pair with maximum sum in a Matrix
- Path with maximum average value
- Find the row with maximum number of 1s
- Find row with maximum sum in a Matrix
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.