Matrix Multiplication Task

Given two sparse matrices MAT1 and MAT2 of integers with dimensions 'N' x 'M' and 'M' x 'P' respectively, the goal is to determine the resulting matrix produced by their multiplication.

A sparse matrix is characterized by having very few non-zero elements.

Input:

The first line contains an integer 'T' indicating the number of test cases.
For each test case, the first line consists of four space-separated integers 'N', 'M', 'M', 'P'.
The following 'N' lines contain 'M' space-separated integers representing 'MAT1'.
The following 'M' lines contain 'P' space-separated integers representing 'MAT2'.

Output:

For each test case, output the resulting matrix 'MAT3' from the multiplication of 'MAT1' and 'MAT2'.
Example:

Suppose 'MAT1' and 'MAT2' are as follows, 'MAT3' is obtained by multiplying them:

1. MAT3[0][0] = MAT1[0][0] * MAT2[0][0] + MAT1[0][1] * MAT2[1][0] = 6
2. MAT3[1][0] = MAT1[1][0] * MAT2[0][0] + MAT1[1][1] * MAT2[1][0] = 0

Constraints:

  • 1 <= 'T' <= 100
  • 1 <= 'N', 'M', 'P' <= 100
  • -105 <= MAT1[i][j], MAT2[i][j] <= 105
Note:
Just implement the function to compute the result; printing is handled elsewhere.
Be the first one to answer
Add answer anonymously...
LTIMindtree Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter