PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Compute dot product of sparse vectors

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency with sparse data representations and algorithmic efficiency by requiring the dot product to be computed from lists of non-zero entries; it falls under the Coding & Algorithms domain and touches on data structures and numerical operations.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Compute dot product of sparse vectors

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem You need to compute the dot product of two sparse vectors of the same dimension. Each vector is provided as a list of non-zero entries sorted by index: - `A = [(i1, v1), (i2, v2), ...]` - `B = [(j1, w1), (j2, w2), ...]` Compute: \[ \sum_{k=0}^{n-1} A[k] \cdot B[k] \] ### Requirements - You **may not** use a hash map / dictionary. - Aim for time proportional to the number of non-zero entries. ### Input/Output - Input: two arrays/lists of pairs `(index, value)` (indices strictly increasing) - Output: the integer/long dot product ### Example - `A = [(0, 1), (3, 2), (10, 5)]` - `B = [(3, 4), (10, 2)]` - Dot product = `2*4 + 5*2 = 18` ### Constraints - Vector dimension `n` can be large (up to 10^9 conceptually) - Number of non-zeros in each vector up to 2*10^5

Quick Answer: This question evaluates proficiency with sparse data representations and algorithmic efficiency by requiring the dot product to be computed from lists of non-zero entries; it falls under the Coding & Algorithms domain and touches on data structures and numerical operations.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Jan 18, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0
Loading...

Problem

You need to compute the dot product of two sparse vectors of the same dimension.

Each vector is provided as a list of non-zero entries sorted by index:

  • A = [(i1, v1), (i2, v2), ...]
  • B = [(j1, w1), (j2, w2), ...]

Compute:

∑k=0n−1A[k]⋅B[k]\sum_{k=0}^{n-1} A[k] \cdot B[k]∑k=0n−1​A[k]⋅B[k]

Requirements

  • You may not use a hash map / dictionary.
  • Aim for time proportional to the number of non-zero entries.

Input/Output

  • Input: two arrays/lists of pairs (index, value) (indices strictly increasing)
  • Output: the integer/long dot product

Example

  • A = [(0, 1), (3, 2), (10, 5)]
  • B = [(3, 4), (10, 2)]
  • Dot product = 2*4 + 5*2 = 18

Constraints

  • Vector dimension n can be large (up to 10^9 conceptually)
  • Number of non-zeros in each vector up to 2*10^5

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta 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.