# Category Archives: Matrix

## Farthest distance of a 0 from the center of a 2-D matrix

Given a matrix of odd order mat, the task is to find the farthest distance of a 0 from the center of the matrix. Distance… Read More »

## Maximum difference of indices (i, j) such that A[i][j] = 0 in the given matrix

Given a matrix of order n*n, the task is to find the maximum value of |i-j| such that Aij = 0. Given matrix must contain… Read More »

## Number of cells in the right and left diagonals passing through (x, y) in a matrix

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… Read More »

## Magical Pattern

Given an integer N as input, the task is to print the Magical Pattern as given below: N . . 3 2 1 2 3… Read More »

## Finding inverse of a matrix using Gauss – Jordan Method | Set 2

Given a Matrix, the task is to find the inverse of this Matrix using the Gauss-Jordan method. What is matrix? Matrix is an ordered rectangular… Read More »

## Find maximum path length in a binary matrix

Given a square matrix mat every element of which is either 0 or 1. A value 1 means connected and 0 means not connected. The… Read More »

## Find single Movement in a Matrix

Given four integers x1, y1 and x2, y2 which represent two locations in an infinite 2D-Matrix, the task is to find whether it is possible… Read More »

## Search in a sorted 2D matrix (Stored in row major order)

Given an integer ‘K’ and a row-wise sorted 2-D Matrix i.e. the matrix has the following properties: Integers in each row are sorted from left… Read More »

## Count Magic squares in a grid

Given an Grid of integers. The task is to find total numbers of 3 x 3 (contiguous) Magic Square subgrids in the given grid. A… Read More »

## Find number of cavities in a matrix

Count the number of the cavity in the 2d matrix, a cavity is defined as all the surrounding number are greater than the mid number.… Read More »

## Print the matrix diagonally downwards

Given a matrix of size n*n, print the matrix in the following pattern. Output: 1 2 5 3 6 9 4 7 10 13 8… Read More »

## Find number of Positional Elements

Given a matrix of integers, task is to find out number of positional elements. A positional element is one which is either minimum or maximum… Read More »

## Finding the probability of a state at a given time in a Markov chain | Set 2

Given a Markov chain G, we have the find the probability of reaching the state F at time t = T if we start from… Read More »

## Count majority element in a matrix

Given a NxM matrix of integers containing duplicate elements. The task is to find the count of all majority occurring elements in the given matrix,… Read More »

## Sum of all maximum frequency elements in Matrix

Given a NxM matrix of integers containing duplicate elements. The task is to find the sum of all maximum occurring elements in the given matrix.… Read More »