Grokking Coding Mock Interview
Ask Author
Back to course home

0% completed

Solution: Dot Product of Two Sparse Vectors
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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 nums
  • dotProduct(vec) Calculates the dot product between the vec and instance of Solution.

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.

.....

.....

.....

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