# Category Archives: Matrix

## Create a matrix with alternating rectangles of O and XMay 14, 2014

Write a code which inputs two numbers m and n and creates a matrix of size m x n (m rows and n columns) in which every elements is either X or 0.

## Kth smallest element in a row-wise and column-wise sorted 2D array | Set 1April 16, 2014

Given an n x n matrix, where every row and column is sorted in non-decreasing order. Find the kth smallest element in the given 2D array.

## Count all possible paths from top left to bottom right of a mXn matrixDecember 31, 2013

The problem is to count all the possible paths from top left to bottom right of a mXn matrix with the constraints that from each cell you can either move only to right or down

## Print all possible paths from top left to bottom right of a mXn matrixDecember 22, 2013

The problem is to print all the possible paths from top left to bottom right of a mXn matrix with the constraints that from each cell you can either move only to right or down.

## Print Matrix DiagonallyMarch 14, 2013

Given a 2D matrix, print all elements of the given matrix in diagonal order. For example, consider the following 5 X 4 input matrix.

## Dynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix)February 27, 2013

Given a 2D array, find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with blue rectangle and sum of this subarray is 29.

## Find the number of islands | Set 1 (Using DFS)October 17, 2012

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands Input : mat[][] = {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 0, 1, 1}, {0, 0, 0, 0, 0}, {1, 0, 1, 0, 1}… Read More »

## Inplace (Fixed space) M x N size matrix transpose | UpdatedOctober 16, 2012

About four months of gap (missing GFG), a new post. Given an M x N matrix, transpose the matrix without auxiliary memory.

## Print unique rows in a given boolean matrixSeptember 28, 2012

Given a binary matrix, print all unique rows of the given matrix.

## Find the row with maximum number of 1sSeptember 23, 2012

Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s.

## Magic SquareJuly 25, 2012

A magic square of order n is an arrangement of n^2 numbers, usually distinct integers, in a square, such that the n numbers in all rows,