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
- Number of cells in a matrix that satisfy the given condition
- Find Number of Even cells in a Zero Matrix after Q queries
- Number of cells in matrix which are equidistant from given two points
- Print a matrix in alternate manner (left to right then right to left)
- Program to print the Diagonals of a Matrix
- 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
- Find safe cells in a matrix
- Find whether there is path between two cells in matrix
- Unique cells in a binary matrix
- Finding the converging element of the diagonals in a square matrix
- Swap major and minor diagonals of a square matrix
- Row-wise common elements in two diagonals of a square 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.