

Sparse Vector: Initialize the vector.
dotProduct(vec2): Implement the dot product between vector ‘sparseVector’ and ‘vec2’.
‘N’ = 6, ‘vec1’ = {2, 4, 0, 0, 1, 0}, ‘vec2’ = {0, 0, 3, 0, 5, 0}
Now in this example, the dot product of these two vectors is (2 * 0) + (4 * 0) + (0 * 3) + (0 * 0) + (1 * 5) + (0 * 0) = 5. Hence the final answer is 5.
The first line of input format contains ‘T’, denoting the number of test cases. Then each test case follows.
The first line of each test case contains an integer ‘N’, Denoting the number of elements in the array ‘vec1’ and ‘vec2’.
The second line of the test case contains an array of ‘N’ integers denoting the elements of the array ‘vec1’.
The third line of the test case contains an array of ‘N’ integers denoting the elements of array ‘vec2’.
For each test case, print a single integer “ans” denoting the dot product of the two vectors.
Output for every query will be printed in a separate line.
You are not required to print anything explicitly. It has already been taken care of. Just implement the two functions of class ‘sparseVector’.
1 <= T <= 100
2 <= N <= 10^5
0 <= vec1[i], vec2[i] <= 100
Time Limit: 1 sec
We will declare a hash map ‘vecToMap’ and hash all the values to the hash map. Now in the constructor function, we will update the hash map and in the dot product function, we will calculate the dot product of all the elements which have the same index.
The steps are as follows:
We will declare a vector of pairs ‘vecToPair’ where each pair will have the first element as an index and the second element as value at that index. Now in the constructor function, we will update the index-value pair vector and in the dot product function, we will calculate the dot product of all the elements which have the same index.
The steps are as follows: