Multiply Two Grids
a is a grid with n rows and m columns and b is a grid with m rows and p columns, both given as lists of rows. Return their matrix product: a grid with n rows and p columns in which the cell in row i and column j is the sum of a[i][k] * b[k][j] over every k from 0 to m - 1. Do not change a or b.
Example 1
a [[1,2],[3,4]]
b [[5,6],[7,8]]
returns [[19,22],[43,50]]
The top-left cell is 1 * 5 + 2 * 7 = 19 and the bottom-right cell is 3 * 6 + 4 * 8 = 50.
Example 2
a [[1,0,-1]]
b [[2],[3],[4]]
returns [[-2]]
A single row times a single column gives one cell: 1 * 2 + 0 * 3 + (-1) * 4 = -2.
Constraints
1 <= n, m, p <= 8len(b) == len(a[0]), and within each grid every row has the same length-10 <= a[i][k], b[k][j] <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.