PIXELBANKv8.2.1
Menu

Dot Product of Two Sparse Vectors

Given two sparse vectors represented as arrays, compute their dot product efficiently.

A sparse vector has mostly zero elements. Store only non-zero elements for efficiency.

Example:

Input:
1,0,0,2,3
0,3,0,4,0
Output:
8
Reasoning:
  • The input represents two sparse vectors: [1,0,0,2,3][1, 0, 0, 2, 3] and [0,3,0,4,0][0, 3, 0, 4, 0]
  • To compute the dot product, we multiply corresponding elements: 10+03+00+24+301 \cdot 0 + 0 \cdot 3 + 0 \cdot 0 + 2 \cdot 4 + 3 \cdot 0
  • This simplifies to: 0+0+0+8+0=80 + 0 + 0 + 8 + 0 = 8
  • The final output is the result of this computation: 88

Constraints:

  • 1 <= len(nums1) == len(nums2) <= 10^5
  • 0 <= nums[i] <= 100
Editor

Test Results

0/0
Run code to see test results.