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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- 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
- Check if a Queen can attack a given cell on chessboard
- Total position where king can reach on a chessboard in exactly M moves | Set 2
- Count positions in a chessboard that can be visited by the Queen which are not visited by the King
- Check if all enemies are killed with bombs placed in a matrix
- Probability of Knight to remain in the chessboard
- Check if the given chessboard is valid or not
- Chessboard Pawn-Pawn game
- Puzzle | Minimum colors required to color a chessboard with no two given pair threatening each other
- Check if any King is unsafe on the Chessboard or not
- Find all the queens attacking the king in a chessboard
- Maximum mirrors which can transfer light from bottom to right
- Maximum number of customers that can be satisfied with given quantity
- Maximum increase in value of Matrix to keep maximum rows and columns unchanged
- Number of cells a queen can move with obstacles on the chessborad
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.