# Category Archives: Matrix

## Collect maximum points in a grid using two traversalsAugust 11, 2015

Given a matrix where every cell represents points. How to collect maximum points using two traversals under following conditions?

## Rotate Matrix ElementsJuly 30, 2015

Given a matrix, clockwise rotate elements in it.

## Find sum of all elements in a matrix except the elements in row and/or column of given cell?July 28, 2015

Given a 2D matrix and a set of cell indexes e.g., an array of (i, j) where i indicates row and j column. For every given cell index (i, j), find sums of all matrix elements except the elements present in i’th row and/or j’th column.

## Count number of islands where every island is row-wise and column-wise separatedFebruary 27, 2015

Given a rectangular matrix which has only two possible values ‘X’ and ‘O’. The values ‘X’ always appear in form of rectangular islands and these islands are always row-wise and column-wise separated by at least one line of ‘O’s.

## Find a common element in all rows of a given row-wise sorted matrixFebruary 13, 2015

Given a matrix where every row is sorted in increasing order. Write a function that finds and returns a common element in all rows. If there is no common element, then returns -1.

## Given a matrix of ‘O’ and ‘X’, replace ‘O’ with ‘X’ if surrounded by ‘X’December 31, 2014

Given a matrix where every element is either ‘O’ or ‘X’, replace ‘O’ with ‘X’ if surrounded by ‘X’. A ‘O’ (or a set of ‘O’) is considered to be by surrounded by ‘X’ if there are ‘X’ at locations just below, just above, just left and just right of it.

## Given a matrix of ‘O’ and ‘X’, find the largest subsquare surrounded by ‘X’December 22, 2014

Given a matrix where every element is either ‘O’ or ‘X’, find the largest subsquare surrounded by ‘X’.

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