Matrix Multiplication

Start Timer

0:00:00

Upvote
0
Downvote
Save question
Mark as completed
View comments

Given two matrices A and B, return their product matrix.

Matrix multiplication is defined only if the number of columns in matrix A is equal to the number of rows in matrix B.

You must compute the result without using any built-in matrix multiplication libraries.

Example 1

Input

A = [[1,2],
     [3,4]]
B = [[5,6],
     [7,8]]

Output

def multiply(A, B) ->
[[19,22],
 [43,50]]

Example 2

Input

A = [[1,0,2],
     [-1,3,1]]
B = [[3,1],
     [2,1],
     [1,0]]

Output

def multiply(A, B) ->
[[5,1],
 [4,2]]

Constraints

  • A - m x n integer matrix
  • B - n x p integer matrix
  • 1 <= m, n, p <= 100
  • -100 <= A[i][j], B[i][j] <= 100
  • The input matrices are always valid for multiplication
.
.
.
.
.


Comments

Loading comments