Category Archives: Matrix

Maximum XOR value in matrix

Given a square matrix (N X N), the task is to find the maximum XOR value of a complete row or a complete column. Examples: Input : N = 3 mat[3][3] = {{1, 0, 4}, {3, 7, 2}, {5, 9, 10} }; Output : 14 We get this maximum XOR value by doing XOR of… Read More »

Path with maximum average value

Given a square matrix of size N*N, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells which starts from top left cell move only right or down and ends on bottom right cell. We want to find a path with maximum average over all existing… Read More »

Maximum mirrors which can transfer light from bottom to right

A square matrix is given in which each cell represents either a blank or an obstacle. We can place mirrors at blank positionl. All mirrors will be situated at 45 degree, i.e. they can transfer light from bottom to right if no obstacle is there in their path. In this question we need to count… Read More »

Nearest 1 in a binary matrix

Given a binary matrix of order m*n, the task is to find the distance of nearest 1 for each 0 in the matrix and print final distance matrix. From any cell (i,j), we can move only in four directions up, down, left and right. Note : Distance from one cell to immediate another cell is… Read More »

Saddle point in a matrix

Given a matrix of n x n size, the task is to find saddle point of the matrix. A saddle point is an element of the matrix such that it is the minimum element in its row and maximum in its column. Examples: Input: Mat[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8,… Read More »

Latin Square

A Latin Square is a n x n grid filled by n distinct numbers each appearing exactly once in each row and column. Given an input n, we have to print a n x n matrix consisting of numbers from 1 to n each appearing exactly once in each row and each column. Examples: Input:… Read More »