Given two matrices A and B of order p x q (or q X p) and r x s ( or s X r). The task is to find the minimum number of elements to be added to any of the two matrices to make them multiplicative.
Two matrices are multiplicative if the number of columns in one matrix is equal to the number of rows in the other matrix.
Input: p = 2, q = 3, r = 5, s = 6
Two columns can be added to make q = 5.
To add two columns, the number of elements will be added 2 * no. of rows i.e. 2 * 2 = 4
Input: p = 11, q = 5, r = 10, s = 11
- If the number of columns in one matrix is equal to the number of rows in the other matrix, then no extra elements are required to be added.
- If they are not equal, we have to add either some extra columns in one matrix or some extra rows in the other matrix.
So, calculate the number of extra elements in both condition and print the minimum one.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum value to be added to X such that it is at least Y percent of N
- Count of matrices (of different orders) with given number of elements
- Print elements that can be added to form a given sum
- Minimum number of Parentheses to be added to make it valid
- Find the minimum number to be added to N to make it a power of K
- Minimum difference between adjacent elements of array which contain elements from each row of a matrix
- XOR of XORs of all sub-matrices
- Different Operations on Matrices
- Find the first, second and third minimum elements in an array
- Sum of all minimum frequency elements in Matrix
- Sum of minimum elements of all possible sub-arrays of an array
- Kronecker Product of two matrices
- Java Program to Add two Matrices
- Python program to add two Matrices
- Count sub-matrices having sum divisible 'k'
- Number of square matrices with all 1s
- Program to multiply two matrices
- Program for addition of two matrices
- Program for subtraction of matrices
- Find the intersection of two Matrices
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.