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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Maximum non-attacking Knights that can be placed on an N*M Chessboard
- 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
- Maximum sum of elements from each row in the matrix
- Submatrix of given size with maximum 1's
- Find a sub matrix with maximum XOR
- Find row with maximum sum in a Matrix
- Maximum sum path 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.