# Category Archives: Matrix

## Print a given matrix in reverse spiral formJune 10, 2017

Given a 2D array, print it in reverse spiral form. We have already discussed Print a given matrix in spiral form. This article discusses how… Read More »

## Maximum sum in a 2 x n grid such that no two elements are adjacentJune 8, 2017

Given a rectangular grid of dimension 2 x n. We need to find out the maximum sum such that no two chosen numbers are adjacent,… Read More »

## Find distinct elements common to all rows of a matrixJune 5, 2017

Given a n x n matrix. The problem is to find all the distinct elements common to all rows of the matrix. The elements can… Read More »

## Find a peak element in a 2D arrayMay 14, 2017

An element is a peak element if it is greater than or equal to its four neighbors, left, right, top and bottom. For example neighbors… Read More »

## Search element in a sorted matrix

Given a sorted matrix mat[n][m] and an element ‘x’. Find position of x in the matrix if it is present, else print -1. Matrix is… Read More »

## Find difference between sums of two diagonalsApril 16, 2017

Given a matrix of n X n. The task is to calculate the absolute difference between the sums of its diagonal. Examples: Input : mat[][]… Read More »

## Largest sum Zigzag sequence in a matrix

Given a matrix of size n x n, find sum of the Zigzag sequence with the largest sum. A zigzag sequence starts from the top… Read More »

## Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)April 15, 2017

Given two values m and n, fill a matrix of size ‘m*n’ in spiral (or circular) fashion (clockwise) with natural numbers from 1 to m*n.… Read More »

## Find number of endless pointsApril 11, 2017

Given a binary N x N matrix, we need to find the total number of matrix positions from which there is an endless path. Any… Read More »

## Program for Sudoku GeneratorApril 10, 2017

Background: Following are the rules of Suduku for a player. In all 9 sub matrices 3×3 the elements should be 1-9, without repetition. In all… Read More »

## Program for Conway’s Game Of LifeApril 3, 2017

Initially, there is a grid with some cells which may be alive or dead. Our task to generate the next generation of cells based on… Read More »

## Number of pair of positions in matrix which are not accessibleMarch 31, 2017

Given a positive integer N. Consider a matrix of N X N. No cell can be accessible from any other cell, except the given pair… Read More »

## Maximum sum of hour glass in matrixMarch 20, 2017

Given a 2D matrix, the task is that we find maximum sum of a hour glass. An hour glass is made of 7 cells in… Read More »

## Number of decisions to reach destinationMarch 19, 2017

Given a grid which consists of 4 types of characters : ‘B’ ‘.’ ‘S’ and ‘D’. We need to reach D starting from S, at… Read More »

## Rotate a matrix by 90 degree without using any extra space | Set 2March 12, 2017

Given a square matrix, turn it by 90 degrees in anti-clockwise direction without using any extra space. Examples: Input 1 2 3 4 5 6… Read More »