Reported November 2023
Modularmatrix

Dense Matrix Multiplication

Reported by candidates from Modular's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Modular OA. Under 2s to a working solution.
Founder's read

Modular's November 2023 OA boils down to one thing: matrix multiplication with three nested loops. The hinted pattern says breadth-first-search, but ignore it. Nothing here is a graph. If you're taking this assessment in the next day or two, expect a plain m x k times k x n product where each cell is a row-column dot product. It looks easy, and that's the danger, because the bugs live in the dimensions, not the idea. StealthCoder is the safety net running invisibly during the live OA if you blank on the loop order or the indexing.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The problem reduces to a triple loop. For each i in 0..m-1 and each j in 0..n-1, sum left[i][t] * right[t][j] for t in 0..k-1. That's O(m*k*n), and with every dimension capped at 100 you're at about a million operations. No optimization needed. The common pitfalls are all dimension bugs. Sizing the result as m x n, not k x k. Swapping the indices on right so you read right[j][t]. Forgetting to initialize the accumulator to zero per cell. Example 3 is a good check, since a 2x1 times 1x3 gives a 2x3 result. Negative values are fine, and results fit in 32 bits, so no overflow handling is required. Write it cleanly, test the 1x1 case, and you're done. If your mind goes blank mid-assessment, StealthCoder can supply the loop structure from the live screen without the proctor seeing it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Dense Matrix Multiplication cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as sparse matrix multiplication. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Modular's OA.

Modular reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Dense Matrix Multiplication FAQ

How hard is the Modular Dense Matrix Multiplication question really?+

Easy on concept, with small room for error. It's the textbook definition of matrix product. The only real risk is mixing up indices or the output dimensions. If you can write three nested loops and allocate an m by n result, you can pass it.

What's the trick to Dense Matrix Multiplication?+

There isn't a clever one. Each result cell [i][j] is the sum over t of left[i][t] times right[t][j]. Allocate the result as m rows by n columns, loop i, j, t, and accumulate. Keep the innermost loop over k.

Is BFS needed even though the hint says breadth-first-search?+

No. The hint is misleading here. There's no graph, no traversal, and no shortest path. This is pure array and matrix arithmetic with nested loops. Don't waste time looking for a search structure.

Do I need to worry about overflow or optimization?+

No. Dimensions max out at 100, so the work is about a million multiply-adds. Values are between -100 and 100, and the problem guarantees every result fits in a signed 32-bit integer. A straightforward triple loop is fine.

How do I prepare for this in 48 hours?+

Write the triple loop from memory twice. Then trace Example 3 by hand, a 2x1 times 1x3, to confirm your dimension handling. Also test a 1x1 case. That covers nearly every way this question goes wrong.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Modular.

OA at Modular?
Invisible during screen share
Get it