Click4Ai

31.

Easy

Write a function dot_product(v1, v2) that computes the dot product of two vectors without using np.dot(). The dot product is the sum of element-wise products.

**Formula:** dot(v1, v2) = v1[0]*v2[0] + v1[1]*v2[1] + ... + v1[n]*v2[n]

Example:

Input: v1 = [1, 2, 3], v2 = [4, 5, 6]

Output: 32

**Explanation:** 1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32

Constraints:

  • Both vectors have the same length
  • 1 <= len(v) <= 1000
  • Test Cases

    Test Case 1
    Input: [1, 2, 3], [4, 5, 6]
    Expected: 32
    Test Case 2
    Input: [1, 0, 0], [0, 1, 0]
    Expected: 0
    Test Case 3
    Input: [2, 3], [4, 5]
    Expected: 23
    + 2 hidden test cases