Implementing sparse matrix-vector multiply with CSR format
This medium-difficulty coding problem tests whether you understand compressed sparse row (CSR) format and can implement an efficient, correct matrix-vector product. Firms like Nvidia care about this because sparse operations power GPU workloads in graph algorithms, physics simulations, and machine learning — and CSR is the industry standard for storing sparse matrices compactly.
The core challenge is correctly navigating the three-array CSR representation: reading the row boundaries from row_ptr, fetching the corresponding nonzero values and their column indices, then accumulating dot products. The solution is straightforward once you understand how row_ptr acts as a pointer into the values array, but off-by-one errors and edge cases (empty matrices, single-element rows) are common trip-ups under time pressure.
- Array indexing and pointer arithmetic
- Dense versus sparse data layout and memory efficiency
- Boundary conditions and loop invariants