Compute dot product of sparse vectors
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([(0,1),(3,2),(10,5)], [(3,4),(10,2)])
Expected Output: 18
Explanation: Prompt example.
Input: ([], [(1,5)])
Expected Output: 0
Explanation: One empty vector.
Input: ([(1,-2),(4,3)], [(1,5),(3,7),(4,-1)])
Expected Output: -13
Explanation: Negative values.
Hints
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.