# Category: Matrix

## Collect maximum points in a matrix by satisfying given constraints

Given a M x N matrix where each cell can have value of 1, 0 or -1, where -1 denotes a unsafe cell, collect maximum number of ones starting from first cell and by visiting only safe cells (i.e. 0 or 1). We are allowed to go only left or down if the row is …

Read More Collect maximum points in a matrix by satisfying given constraints

## Count number of paths in a matrix with given cost to reach destination cell

Given a M x N matrix where each cell have non-negative cost associated with it, count number of paths to reach last cell (M-1, N-1) of the matrix from its first cell (0, 0) such that path has given cost. We can only move one unit right or one unit down from any cell. i.e. …

Read More Count number of paths in a matrix with given cost to reach destination cell

## Find longest sequence formed by adjacent numbers in the matrix

Given a N x N matrix where each cell has distinct value in the 1 to N * N. Find the longest sequence formed by adjacent numbers in the matrix such that for each number, the number on the adjacent neighbor is +1 its value.

Read More Find longest sequence formed by adjacent numbers in the matrix

## Find the minimum cost to reach last cell of the matrix from its first cell

Given a M x N matrix where each cell has a cost associated with it, find the minimum cost to reach last cell (M-1, N-1) of the matrix from its first cell (0, 0). We can only move one unit right or one unit down from any cell. i.e. from cell (i, j), we can …

Read More Find the minimum cost to reach last cell of the matrix from its first cell

## Calculate sum of all elements in a sub-matrix in constant time

Given a M x N matrix and two coordinates (p, q) and (r, s) which represents top-left and bottom-right coordinates of a sub-matrix of the given matrix, calculate the sum of all elements present in the sub-matrix in O(1) time. Here, 0 < = p < r < M and 0

Read More Calculate sum of all elements in a sub-matrix in constant time

## Find probability that a person is alive after taking N steps on the island

Given an island in the form of square matrix and a point inside the matrix where a person is standing. The person is allowed to move one step in any direction (right, left, top, down) on the matrix. If he steps outside the matrix, he dies. Calculate the probability that he is alive after he …

Read More Find probability that a person is alive after taking N steps on the island