# Category Archives: Matrix

## Flood fill Algorithm – how to implement fill() in paint?December 16, 2014

In MS-Paint, when we take the brush to a pixel and click, the color of the region of that pixel is replaced with a new selected color. Following is the problem statement to do this task.

## Print all elements in sorted order from row and column wise sorted matrixOctober 22, 2014

Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of matrix in sorted order.

## Mobile Numeric Keypad ProblemSeptember 26, 2014

Given the mobile numeric keypad. You can only press buttons that are up, left, right or down to the current button. You are not allowed to press bottom row corner buttons (i.e. * and # ).

## Given an n x n square matrix, find sum of all sub-squares of size k x kSeptember 22, 2014

Given an n x n square matrix, find sum of all sub-squares of size k x k where k is smaller than or equal to n.

## 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 »