Category Archives: Matrix

Total coverage of all zeros in a binary matrix

Given a binary matrix that is, it contains 0s and 1s only, we need to find sum of coverage of all zeros of the matrix where coverage for a particular 0 is defined as total number of ones around a zero in left, right, up and bottom directions. The ones can be anywhere till corner… Read More »

Number of palindromic paths in a matrix

Given a matrix containing lower alphabetical characters only, we need to count number of palindromic paths in given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. Examples: Input : mat[][] =… Read More »

Print cells with same rectangular sums in a matrix

Given a matrix of m x n matrix, we need to print all those cells at which sum of sub-matrix ended at this cell and sub-matrix starting at this cell is equal to remaining elements. For better understanding please see below diagram, Examples: Input : mat[][] = {1, 2, 3, 5, 4, 1, 0, 2,… Read More »

Print matrix in diagonal pattern

Given a matrix of n*n size, the task is to print its elements in diagonally pattern. Input : mat[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Output : 1 2 4 7 5 3 6 8 9. Explanation: We start from 1 Then from upward to downward diagonally i.e. 2 and 4… Read More »