PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Voleon

Implement sparse matrix addition and multiplication

Last updated: May 23, 2026

Quick Overview

This question evaluates implementation skills for sparse matrix addition and multiplication, focusing on data structure selection, algorithmic complexity, memory efficiency, and explicit error handling within the Coding & Algorithms domain and the linear algebra/data-structures crossover.

  • nan
  • Voleon
  • Coding & Algorithms
  • Software Engineer

Implement sparse matrix addition and multiplication

Company: Voleon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: nan

Interview Round: Technical Screen

Implement sparse-matrix operations with explicit error handling. ### Sparse matrix A matrix `A` has dimensions `r x c` and is **sparse**, meaning most entries are zero. You may choose a representation (e.g., hashmap/dictionary keyed by `(row, col)` for non-zero values, or compressed rows), but your implementation should be efficient for sparse inputs. ### Tasks Implement: 1. `add(A, B)` → returns `A + B` 2. `mul(A, B)` → returns `A * B` ### Requirements - If dimensions are incompatible: - For addition: `A` and `B` must have the same shape. - For multiplication: `A` is `r x k`, `B` must be `k x c`. - Incompatible dimensions must trigger clear error handling (e.g., raise an exception or return an error value, as specified by your interface). - Preserve sparsity: avoid iterating over all `r*c` cells. ### Input/Output (one reasonable interface) - Input: two sparse matrices - Output: a sparse matrix (or error) ### Constraints (reasonable interview constraints) - Up to `10^5` non-zero entries per matrix. - Dimensions can be large (e.g., up to `10^9`), so dense storage is not allowed.

Quick Answer: This question evaluates implementation skills for sparse matrix addition and multiplication, focusing on data structure selection, algorithmic complexity, memory efficiency, and explicit error handling within the Coding & Algorithms domain and the linear algebra/data-structures crossover.

Related Interview Questions

  • Solve classic coding interview problems - Voleon (hard)
  • Count White Balls After K Steps - Voleon (hard)
  • Count queen attacks on points with blockers - Voleon (nan)
  • Validate whether a binary string is good - Voleon (nan)
  • Simulate an exchange and participation-rate trading - Voleon (nan)
Voleon logo
Voleon
Dec 9, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
34
0

Implement sparse-matrix operations with explicit error handling.

Sparse matrix

A matrix A has dimensions r x c and is sparse, meaning most entries are zero.

You may choose a representation (e.g., hashmap/dictionary keyed by (row, col) for non-zero values, or compressed rows), but your implementation should be efficient for sparse inputs.

Tasks

Implement:

  1. add(A, B) → returns A + B
  2. mul(A, B) → returns A * B

Requirements

  • If dimensions are incompatible:
    • For addition: A and B must have the same shape.
    • For multiplication: A is r x k , B must be k x c .
    • Incompatible dimensions must trigger clear error handling (e.g., raise an exception or return an error value, as specified by your interface).
  • Preserve sparsity: avoid iterating over all r*c cells.

Input/Output (one reasonable interface)

  • Input: two sparse matrices
  • Output: a sparse matrix (or error)

Constraints (reasonable interview constraints)

  • Up to 10^5 non-zero entries per matrix.
  • Dimensions can be large (e.g., up to 10^9 ), so dense storage is not allowed.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Voleon•More Software Engineer•Voleon Software Engineer•Voleon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.