# Category Archives: Matrix

## Maximize sum of K elements selected from a Matrix such that each selected element must be preceded by selected row elements

Given a 2D array arr[][] of size N * M, and an integer K, the task is to select K elements with maximum possible sum… Read More »

## Maximize minimum of array generated by maximums of same indexed elements of two rows of a given Matrix

Given a matrix mat[][] of N rows and M columns, the task is to choose any two rows(i, j) (0 ≤ i, j ≤ N… Read More »

## Maximize count of rows consisting of equal elements by flipping columns of a Matrix

Given a binary matrix, mat[][] of dimensions N * M, the task is to maximize the count of rows consisting only of equal elements by… Read More »

## Modify matrix by increments such that no pair of adjacent elements are equal

Given a square matrix mat[][] of size N * N, the task is to print the matrix after incrementing matrix elements such that no two… Read More »

## Print matrix elements from top-left to bottom right in diagonally upward manner

Given a vectors of vectors arr[], the task is to print the elements of arr[] in the diagonally upwards order as illustrated below. Examples:  Input:… Read More »

## Maximum non-negative product of a path from top left to bottom right of given Matrix

Given an integer matrix mat[][] of dimensions N * M,  the task is to print the maximum product of matrix elements in the path from… Read More »

## Minimum number of flips required such that the last cell of matrix can be reached from any other cell

Given a matrix arr[][] of dimensions N * M where each cell consists of characters ‘R’ or ‘D’ except the cell arr[N][M] which contains ‘F’.… Read More »

## Maximize sum of diagonal of a matrix by rotating all rows or all columns

Given a square matrix, mat[][] of dimensions N * N, the task is find the maximum sum of diagonal elements possible from the given matrix… Read More »

## Replace specified matrix elements such that no two adjacent elements are equal

Given a matrix arr[][] of dimensions N * M, consisting of ‘O’ or ‘F’, where ‘O’ denotes obstacles and ‘F’ denotes free spaces, the task… Read More »

## Check if given string satisfies the following conditions

Given a string S of length L, where L is a perfect square, the task is to check if the given string satisfies the following… Read More »

## Smallest submatrix required to be removed such that sum of the remaining matrix is divisible by K

Given a 2D matrix mat[][] of size N * M and a positive integer K, the task is to find the area of the smallest… Read More »

## Construct a Matrix such that each cell consists of sum of adjacent elements of respective cells in given Matrix

Given a matrix arr[][] of dimensions N * M, the task is to generate a matrix such that any cell (r, c) stores the sum… Read More »

## Java Program to Display Lower Triangular Matrix

Lower Triangular Matrix is a square matrix in which all the elements above the principal diagonal are 0. If the matrix is not a square… Read More »

## Check if rows of a Matrix can be rearranged to make Bitwise XOR of first column non-zero

Given a matrix mat[][] of size N * M, the task is to check if it is possible to rearrange the row elements of the… Read More »

## Print a 2D Array or Matrix using single loop

Given a matrix mat[][] of N * M dimensions, the task is to print the elements of the matrix using a single for loop. Examples:… Read More »