Find row and column pair in given Matrix with equal row and column sum
Given a matrix Mat of size N x M, the task is to find all the pairs of rows and columns where the sum of elements in the row is equal to the sum of elements in the columns. Examples: Input: M = {{1, 2, 2}, {1, 5, 6}, {3, 8, 9}}Output: {{1, 1}}Explanation: The sum of elements of rows and columns of matrix M are: C = 1C = 2C = 3Sum of RowsR = 11225R
8 min read
Sum of Matrix where each element is sum of row and column number
Given two numbers M and N denoting the number of rows and columns of a matrix A[] where A[i][j] is the sum of i and j (indices follow 1 based indexing), the task is to find the sum of elements of the matrix. Examples: Input: M = 3, N = 3Output: 36Explanation: A[]: {{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}. Sum of matrix: 36. Input: M = 3, N = 4Output: 54Ex
14 min read
Generate a Matrix such that given Matrix elements are equal to Bitwise OR of all corresponding row and column elements of generated Matrix
Given a matrix B[][] of dimensions N * M, the task is to generate a matrix A[][] of same dimensions that can be formed such that for any element B[i][j] is equal to Bitwise OR of all elements in the ith row and jth column of A[][]. If no such matrix exists, print "Not Possible". Otherwise, print the matrix A[][]. Examples: Input: B[][] = {{1, 1, 1}
11 min read
Minimum element of each row and each column in a matrix
Given a matrix, the task is to find the minimum element of each row and each column. Examples: Input: [1, 2, 3] [1, 4, 9] [76, 34, 21] Output: Minimum element of each row is {1, 1, 21} Minimum element of each column is {1, 2, 3} Input: [1, 2, 3, 21] [12, 1, 65, 9] [11, 56, 34, 2] Output: Minimum element of each row is {1, 1, 2} Minimum element of e
11 min read
Maximum sum of a Matrix where each value is from a unique row and column
Given a matrix of size N X N, the task is to find maximum sum of this Matrix where each value picked is from a unique column for every row.Examples: Input: matrix = [[3, 4, 4, 4], [1, 3, 4, 4], [3, 2, 3, 4], [4, 4, 4, 4]] Output: 16 Explanation: Selecting (0, 1) from row 1 = 4 Selecting (1, 2) from row 2 = 4 Selecting (2, 3) from row 3 = 4 Selectin
8 min read
Construct a Binary Matrix whose sum of each row and column is a Prime Number
Given an integer N, the task is to construct a binary matrix of size N * N such that the sum of each row and each column of the matrix is a prime number. Examples: Input: N = 2 Output: 1 1 1 1 Explanation: Sum of 0th row = 1 + 1 = 2 (Prime number) Sum of 1st row = 1 + 1 = 2 (Prime number) Sum of 0th column = 1 + 1 = 2 (Prime number) Sum of 1st colu
6 min read
Generate a matrix with each row and column of given sum
Given two arrays row[] and col[] of size N and M respectively, the task is to construct a matrix of dimensions N 脳 M such that the sum of matrix elements in every ith row is row[i] and the sum of matrix elements in every jth column is col[j]. Examples: Input: row[] = {5, 7, 10}, col[] = {8, 6, 8}Output: {{0, 5, 0}, {6, 1, 0}, {2, 0, 8}}Explanation:
7 min read
Sum of matrix in which each element is absolute difference of its row and column numbers
Given a positive integer n. Consider a matrix of n rows and n columns, in which each element contain absolute difference of its row number and numbers. The task is to calculate sum of each element of the matrix. Examples : Input : n = 2 Output : 2 Matrix formed with n = 2 with given constraint: 0 1 1 0 Sum of matrix = 2. Input : n = 3 Output : 8 Ma
13 min read
Sum of matrix element where each elements is integer division of row and column
Consider a N X N matrix where each element is divided by a column number (integer division), i.e. mat[i][j] = floor((i+1)/(j+1)) where 0 <= i < n and 0 <= j < n. The task is to find the sum of all matrix elements. Examples : Input : N = 2 Output : 4 2 X 2 matrix with given constraint: 1 0 2 1 Sum of matrix element: 4 Input : N = 3 Outpu
9 min read
Construct a square matrix such that the sum of each row and column is odd
Given an integer N. Then your task is to output a square matrix of length N using the numbers from the range [1, N2] such that the sum of each row and column is odd. Note: If there are multiple solution, then print any of them. Examples: Input: N = 2 Output: {{1, 2}, {4, 3}} Explanation: Let us calculate the sum of each row and col: First row: R1 i
12 min read