← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Implement a class SparseVector that efficiently handles sparse vectors (vectors with mostly zero values) and computes their dot product. The class should support a constructor SparseVector(nums) that takes a list of integers nums and initializes the sparse vector, and a method dotProduct(vec) that computes the dot product between the current sparse vector instance and another sparse vector vec. A sparse vector is a vector containing mostly zeros. Instead of storing all elements including zeros, you should store it efficiently by only keeping track of non-zero values. The dot product of two vectors is calculated by multiplying corresponding elements and summing the results.