FastPrepDense Matrix Multiplication

Dense Matrix Multiplication

Modular logoModular● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given an integer matrix left with dimensions m × k and an integer matrix right with dimensions k × n.

Return their matrix product. Entry [i][j] is the dot product of row i from left and column j from right.

Function

multiplyMatrices(left: int[][], right: int[][]) → int[][]

Examples

Example 1

left = [[1,2],[3,4]]right = [[5,6],[7,8]]return = [[19,22],[43,50]]

Each result entry is one row-column dot product.

Example 2

left = [[1,0,-2]]right = [[3],[4],[5]]return = [[-7]]

The single dot product is 3 + 0 - 10.

Example 3

left = [[2],[3]]right = [[4,5,6]]return = [[8,10,12],[12,15,18]]

A two-by-one matrix times a one-by-three matrix produces two scaled rows.

Constraints

  • 1 <= m, k, n <= 100.
  • Both matrices are rectangular and their inner dimensions match.
  • -100 <= matrix[i][j] <= 100.
  • Every result entry fits a signed 32-bit integer.

More Modular problems

See Modular hiring insights
public int[][] multiplyMatrices(int[][] left, int[][] right) {
    // Return left multiplied by right.
}
left[[1,2],[3,4]]
right[[5,6],[7,8]]
expected[[19,22],[43,50]]
Checking account…