Category Archives: Matrix

Maximum sum of hour glass in matrix

Given a 2D matrix, the task is that we find maximum sum of a hour glass. An hour glass is made of 7 cells in following form. A B C D E F G Examples: Input : 1 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0… Read More »

Number of decisions to reach destination

Given a grid which consists of 4 types of characters : ‘B’ ‘.’ ‘S’ and ‘D’. We need to reach D starting from S, at each step we can go to neighboring cells i.e. up, down, left and right. Cells having character ‘B’ are blocked i.e. at any step we can’t move to cell having… Read More »

Maximum and Minimum in a square matrix.

Given a square matrix of order n*n, find the maximum and minimum from the matrix given. Examples: Input : arr[][] = {5, 4, 9, 2, 0, 6, 3, 1, 8}; Output : Maximum = 9, Minimum = 0 Input : arr[][] = {-5, 3, 2, 4}; Output : Maximum = 4, Minimum = -5 Naive… Read More »

Print matrix in antispiral form

Given a 2D array, the task is to print matrix in anti spiral form: Examples: Output: 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Input : arr[][4] = {1, 2, 3, 4 5, 6, 7, 8 9, 10, 11, 12 13, 14, 15, 16}; Output : 10… Read More »

C Program To Check whether Matrix is Skew Symmetric or not

A Skew Symmetric Matrix or Anti-Symmetric Matrix is a square matrix whose transpose is negative to that of the original matrix. If the entry in the ith row and jth column of a matrix is a[i][j], i.e. if A = (a[i][j]) then the skew symmetric condition is -A = -a[j][i]. Example: Input : matrix: 0… Read More »

Gold Mine Problem

Given a gold mine of n*m dimensions. Each field in this mine contains a positive integer which is the amount of gold in tons. Initially the miner is at first column but can be at any row. He can move only (right->,right up /,right down\) that is from a given cell, the miner can move… Read More »

Easy way to remember Strassen’s Matrix Equation

Strassen’s matrix is a Divide and Conquer method that helps us to multiply two matrices(of size n X n). You can refer to the link, for having the knowledge about Strassen’s Matrix first : Divide and Conquer | Set 5 (Strassen’s Matrix Multiplication) But this method needs to cram few equations, so I’ll tell you… Read More »

Sort a Matrix in all way increasing order

Given a square matrix of order N*N having distinct elements, the task is to sort given matrix in such a way that its rows, columns and both diagonals (diagonal and anti-diagonal) are in increasing order. Examples: Input : arr[3][3] = {1, 4, 2, 3, 5, 6, 9, 7, 8} Output :{1, 2, 3, 4, 5,… Read More »