Back to course home
0% completed
Solution: Dot Product of Two Sparse Vectors
Problem Statement
Given two sparse vectors
, efficiently compute the dot product
of them.
A sparse vector
is one in which most elements are zero.
Implement class Solution
:
Solution(nums)
Initializes the object with the vector numsdotProduct(vec)
Calculates the dot product between thevec
and instance ofSolution
.
Examples
- Example 1:
- Input: vec1 =
[1, 0, 0, 2]
, vec2 =[2, 3, 0, 1]
- Expected Output:
4
- Justification: The dot product is
(1*2) + (0*3) + (0*0) + (2*1) = 2 + 0 + 0 + 2 = 4
.
- Input: vec1 =
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible