Dot Product of Two Sparse Vectors
Problem
Design a class for sparse vectors (mostly zeros) and compute the dot product of two of them efficiently.
Example
a = [1,0,0,2,3], b = [0,3,0,4,0]
Output: 8
Constraints
- n up to 10^5, mostly zeros — store and iterate only the non-zero entries
added …