Given four integers row, col, x and y where row and col are the number of rows and columns of a 2-D Matrix and x and y are the coordinates of a cell in the same matrix, the task is to find number of cells in the left and the right diagonal which the cell (x, y) of the matrix is associated with.
Input: row = 4, col = 3, x = 2, y = 2
Output: 3 3
The number of cells in the left and the right diagonals of (2, 2) are 3 and 3 respectively.
Input: row = 4, col = 5, x = 2, y = 2
Output: 4 3
- Calculate the number of cells in the upper left part and lower right part of the left diagonal of the cell (x, y) separately. Then sum them up to get the number of cells in the left diagonal.
- Similarly, calculate the number of cells in the upper right part and lower left part of the right diagonal of the cell (x, y) separately.
Below is the implementation of the above approach:
- Print a matrix in alternate manner (left to right then right to left)
- Unique cells in a binary matrix
- Find safe cells in a matrix
- Find whether there is path between two cells in matrix
- Shortest distance between two cells in a matrix or grid
- Print cells with same rectangular sums in a matrix
- Minimum Numbers of cells that are connected with the smallest path between 3 given cells
- Program to Interchange Diagonals of Matrix
- Efficiently compute sums of diagonals of a matrix
- Sum of both diagonals of a spiral odd-order square matrix
- Row-wise common elements in two diagonals of a square matrix
- Swap major and minor diagonals of a square matrix
- Center element of matrix equals sums of half diagonals
- Find smallest and largest element from square matrix diagonals
- Maximize sum of N X N upper left sub-matrix from given 2N X 2N 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 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.