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:
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
- Count of cells in a matrix whose adjacent cells's sum is prime Number
- Count of cells in a matrix which give a Fibonacci number when the count of adjacent cells is added
- Number of ways to paint K cells in 3 x N grid such that no P continuous columns are left unpainted
- Number of cells in a matrix that satisfy the given condition
- Number of cells in matrix which are equidistant from given two points
- Find Number of Even cells in a Zero Matrix after Q queries
- Print a matrix in alternate manner (left to right then right to left)
- Program to Interchange Diagonals of Matrix
- Program to print the Diagonals of a Matrix
- Sum of both diagonals of a spiral odd-order square matrix
- Sum of all parts of a square Matrix divided by its diagonals
- Find the product of sum of two diagonals of a square Matrix
- Efficiently compute sums of diagonals of a matrix
- Program to print the Diagonals of a Matrix in O(N) time
- Unique cells in a binary matrix