Matrix Multiplication and Parallel Partitions
Problem statement
Multiply an M×K matrix first by a K×N matrix second. Return the M×N matrix whose [r][c] entry is the sum of first[r][k]*second[k][c] over all shared-dimension indices. Leave both inputs unchanged. Values and dimensions guarantee signed32-bit results.
Parallelization follow-up: partition independent output rows, then compare splitting K into partial products and reducing them. The editorials include actual worker implementations for both partitions. The numeric judge checks returned values; it does not require a speedup or measure scheduling performance. Memory-allocation/deallocation is a separate source task and is not certified by this product-only judge.
Tiling follow-up: compute the same product in small blocks and explain how nearby matrix elements can be reused. The report says this coding topic was asked twice, but gives no tile size, device API or memory layout. The editorial uses ordinary CPU loops with an authored tile size of four and handles partial edge tiles. The judge checks the resulting product, not cache traffic, GPU execution or speed.
Function
matrixMultiply(first: int[][], second: int[][]) → int[][]Examples
Example 1
first = [[1,2,3],[4,5,6]]second = [[7,8],[9,10],[11,12]]return = [[58,64],[139,154]]The first row gives 1*7 + 2*9 + 3*11 = 58 and 1*8 + 2*10 + 3*12 = 64. The second row gives 4*7 + 5*9 + 6*11 = 139 and 4*8 + 5*10 + 6*12 = 154.
Example 2
first = [[2,-1]]second = [[3],[4]]return = [[2]]The only dot product is 2*3 + (-1)*4 = 2.
Constraints
1 <= first.length <= 16.1 <= first[r].length <= 512.1 <= second.length <= 512.1 <= second[r].length <= 16.-100 <= every input matrix value <= 100.- Both matrices are rectangular, and every row of first has exactly second.length entries.