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.
- Print elements that can be added to form a given sum
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Program for addition of two matrices
- Program to check if two given matrices are identical
- Multiplication of two Matrices in Single line using Numpy in Python
- Python program to add two Matrices
- Python program to multiply two matrices
- Python List Equality | Program to check if two given matrices are identical
- Kronecker Product of two matrices
- Count pairs from two sorted matrices with given sum
- Find the intersection of two Matrices
- Java Program to Multiply two Matrices of any size
- Java Program to Add two Matrices
- Program to concatenate two given Matrices of same size
- Check if the given two matrices are mirror images of one another
- Program to multiply two matrices
- Count of matrices (of different orders) with given number of elements
- Minimum number of Parentheses to be added to make it valid
- Minimum value to be added to X such that it is at least Y percent of N
- Find the minimum number to be added to N to make it a power of K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.