Algorithm · ByteDance · Medium
Given two sparse vectors, find their dot product. Vectors A and B share a length of n, but nearly all of their entries are zero. Each vector is represented by a list containing only its non-zero entries. A list item has the form (index, value), meaning that the vector holds value at index. Create a function dot_product(A, B) that returns the vectors' dot product, defined as the total of A[i] * B[i] over all indices. Input Format: Two lists of (index, value) pairs…
Checking your access…