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:
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added
- Print a matrix in alternate manner (left to right then right to left)
- Find whether there is path between two cells in matrix
- Find safe cells in a matrix
- Unique cells in a binary matrix
- Shortest distance between two cells in a matrix or grid
- Print cells with same rectangular sums in a matrix
- Program to Interchange Diagonals of Matrix
- Minimum Numbers of cells that are connected with the smallest path between 3 given cells
- Sum of both diagonals of a spiral odd-order square matrix
- Efficiently compute sums of diagonals of a 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
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.