Program to multiply two matricesGiven two matrices, the task is to multiply them. Matrices can either be square or rectangular:Examples: (Square Matrix Multiplication)Input: m1[m][n] = { {1, 1}, {2, 2} }m2[n][p] = { {1, 1}, {2, 2} }Output: res[m][p] = { {3, 3}, {6, 6} }(Rectangular Matrix Multiplication)Input: m1[3][2] = { {1, 1},
7 min read
Check if all rows of a matrix are circular rotations of each otherGiven a matrix of n*n size, the task is to find whether all rows are circular rotations of each other or not. Examples: Input: mat[][] = 1, 2, 3 3, 1, 2 2, 3, 1 Output: Yes All rows are rotated permutation of each other. Input: mat[3][3] = 1, 2, 3 3, 2, 1 1, 3, 2 Output: No Explanation : As 3, 2, 1
8 min read
Count zeros in a row wise and column wise sorted matrixGiven a n x n binary matrix (elements in matrix can be either 1 or 0) where each row and column of the matrix is sorted in ascending order, count number of 0s present in it.Examples: Input: [0, 0, 0, 0, 1][0, 0, 0, 1, 1][0, 1, 1, 1, 1][1, 1, 1, 1, 1][1, 1, 1, 1, 1]Output: 8Input: [0, 0][0, 0]Output:
6 min read
Find pairs with given sum such that elements of pair are in different rowsGiven a matrix of distinct values and a sum. The task is to find all the pairs in a given matrix whose summation is equal to the given sum. Each element of a pair must be from different rows i.e; the pair must not lie in the same row.Examples: Input : mat[][] = {{1, 3, 2, 4}, {5, 8, 7, 6}, {9, 10, 1
15+ min read
Find all permuted rows of a given row in a matrixGiven a matrix mat[][] of order m*n, and an index ind. The task is to find all the rows in the matrix mat[][] which are permutations of rows at index ind.Note: All the elements of a row are distinct.Examples: Input: mat[][] = [[3, 1, 4, 2], [1, 6, 9, 3], [1, 2, 3, 4], [4, 3, 2, 1]] ind = 3 Output: 0
9 min read
Minimum flip required to make Binary Matrix symmetricGiven a Binary Matrix mat[][] of size n x n, consisting of 1s and 0s. The task is to find the minimum flips required to make the matrix symmetric along the main diagonal.Examples : Input: mat[][] = [[0, 0, 1], [1, 1, 1], [1, 0, 0]];Output: 2Value of mat[1][0] is not equal to mat[0][1].Value of mat[2
8 min read