Sparse Matrix Multiplication
Reported by candidates from Netflix's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Netflix OA reported in September 2026 hands you two matrices and one twist: skip the zeros. Example 2 makes it blunt, with a mat1 of all zeros and a product that needs no real multiplication at all. The hinted tag says breadth-first-search, but this is a matrix problem with a loop-order trick. Sizes are tiny (up to 100), so correctness beats cleverness. If you freeze on the loop structure mid-assessment, StealthCoder runs invisibly on your desktop and gives you the solution in real time as a safety net. Know the shape before you open the invite.
The problem
You are given two rectangular integer matrices, mat1 with dimensions m × k and mat2 with dimensions k × n. Return their matrix product product, an m × n matrix. For every valid row i and column j: product[i][j] = mat1[i][0] * mat2[0][j] +... + mat1[i][k - 1] * mat2[k - 1][j] Sparse-matrix requirement Many entries may be 0. Although the matrices use ordinary dense arrays for input and output, design the multiplication so it skips contributions whose left or right factor is 0. Function multiply(mat1: int[][], mat2: int[][]) → int[][] Examples Example 1 mat1 = [[1,0,0],[-1,0,3]] mat2 = [[7,0,0],[0,0,0],[0,0,1]] return = [[7,0,0],[-7,0,3]] The first row has only one nonzero value, so it contributes 1 × [7,0,0]. The second row contributes -1 × [7,0,0] and 3 × [0,0,1], producing [-7,0,3]. Example 2 mat1 = [[0,0],[0,0]] mat2 = [[1,2],[3,4]] return = [[0,0],[0,0]] Every value in mat1 is 0, so there are no nonzero contributions to the product. Example 3 mat1 = [[1,2],[0,3]] mat2 = [[4,0,5],[6,7,0]] return = [[16,14,5],[18,21,0]] For example, product[0][0] = 1 × 4 + 2 × 6 = 16, while product[1][2] = 0 × 5 + 3 × 0 = 0. Constraints 1 ≤ m, k, n ≤ 100. mat1.length = m and every row of mat1 has length k. mat2.length = k and every row of mat2 has length n. -100 ≤ mat1[i][t], mat2[t][j] ≤ 100. The product of the two matrices fits in a signed 32-bit integer matrix.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to stop computing each cell as a dot product. Loop over i and t in mat1 first. If mat1[i][t] is 0, skip it entirely. Otherwise loop j over row t of mat2, and if mat2[t][j] is nonzero, add mat1[i][t] * mat2[t][j] into product[i][j]. That's the whole problem. Example 1 shows it: row [-1,0,3] contributes -1 times row 0 of mat2 and 3 times row 2. The common pitfall is the textbook i, j, t order, which checks zeros too late and does the dense work anyway. Another is forgetting to allocate the m by n result with zeros. Don't reach for BFS because of the hint. Nothing here is a graph. On the live Netflix OA, if you blank on the loop order, StealthCoder is the hedge that shows the skip-zero version while you stay in control of the keyboard.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Sparse 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sparse matrix multiplication. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Netflix's OA.
Netflix reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sparse Matrix Multiplication FAQ
What's the trick in Sparse Matrix Multiplication?+
Reorder the loops. Iterate i, then t, and skip when mat1[i][t] is 0. Only then loop over j in row t of mat2, adding the scaled values into product[i][j]. You never touch the zero contributions, which is exactly what the statement asks for.
Is this really a breadth-first-search problem?+
No. The BFS hint doesn't match anything in the statement. There are no nodes, edges, or levels. It's a matrix multiplication with a zero-skipping optimization. Treat it as plain nested loops over arrays and ignore the graph label.
How hard is this one really?+
Easy to medium. The math is standard matrix multiplication, and the constraints cap everything at 100, so even a dense approach would run fine. The difficulty is showing you honor the sparse requirement by skipping zero factors, not squeezing out performance.
What edge cases should I test?+
Test an all-zero mat1 like Example 2, where the result must be all zeros. Test negative values like -1 in Example 1. Test non-square shapes like the 2 by 2 times 2 by 3 in Example 3. Also check m, k, or n equal to 1.
How do I prepare in 48 hours?+
Write the skip-zero triple loop from memory twice. Run Examples 1 to 3 by hand and confirm the outputs. Then practice allocating the result matrix and indexing rows versus columns correctly. That covers nearly every mistake people make on this problem.