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
- Number of blocks in a chessboard a knight can move to in exactly k moves
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Maximum XOR value in matrix
- Pair with maximum sum in a Matrix
- Find row with maximum sum in a Matrix
- Maximum path sum in matrix
- Maximum sum rectangle in a 2D matrix | DP-27
- Maximum sum of elements from each row in the matrix
- Find the row with maximum number of 1s
- Path with maximum average value
- Maximum difference of indices (i, j) such that A[i][j] = 0 in the given matrix
- Find maximum element of each row in a matrix
- Maximum number of ones in a N*N matrix with given constraints
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.