Given two sparse vectors nums1 and nums2 (arrays that are mostly zeros), compute their dot product. The dot product is the sum of nums1[i] * nums2[i] over all indices i. A sparse representation stores only the non-zero entries so the product skips the many zeros.
Example 1
Input: nums1 = [1,0,0,2,3], nums2 = [0,3,0,4,0]
Output: 8
Explanation: The only index where both vectors are non-zero is 3, so the dot product is 2 * 4 = 8. Every other product includes a 0.
Example 2
Input: nums1 = [0,1,0,0,0], nums2 = [0,0,0,0,2]
Output: 0
Explanation: nums1 is non-zero only at index 1 and nums2 only at index 4. They never overlap, so every product is 0.
Example 3
Input: nums1 = [0,1,0,0,2,0,0], nums2 = [1,0,0,0,3,0,4]
Output: 6
Explanation: Only index 4 is non-zero in both vectors: 2 * 3 = 6. Indices 0 and 6 are non-zero only in nums2, so they add nothing.
Store just the non-zero entries of the first vector as index -> value. Then scan the second vector's non-zeros and multiply only where the first vector also has a non-zero.
Run checks all cases above. Submit evaluates all test cases.