Dense Vector Dot Product
Problem statement
Given two equal-length integer vectors first and second, return their dot product.
The dot product is the sum of first[i] * second[i] over every index. Use 64-bit arithmetic for each product and for the accumulated result.
Function
dotProduct(first: int[], second: int[]) → longExamples
Example 1
first = [1,2,3]second = [4,5,6]return = 32The dot product is 1 * 4 + 2 * 5 + 3 * 6 = 32.
Example 2
first = [0,-3,5,0]second = [7,2,-4,9]return = -26Only the middle entries contribute: -3 * 2 + 5 * -4 = -26.
Example 3
first = [1000000,1000000]second = [1000000,-1000000]return = 0The two products are 10^12 and -10^12, so they cancel.
Constraints
1 ≤ first.length = second.length ≤ 2 * 10^5.-10^6 ≤ first[i], second[i] ≤ 10^6.- The result fits in a signed 64-bit integer.