Click4Ai

35.

Easy

Write a function euclidean_distance(p1, p2) that computes the Euclidean (L2) distance between two points in n-dimensional space.

**Formula:** d = sqrt(sum((p1[i] - p2[i])^2))

Example:

Input: p1 = [0, 0], p2 = [3, 4]

Output: 5.0

**Explanation:** sqrt((3-0)^2 + (4-0)^2) = sqrt(9 + 16) = 5.0

Constraints:

  • Both points have the same dimensionality
  • Return a float
  • Test Cases

    Test Case 1
    Input: [0, 0], [3, 4]
    Expected: 5.0
    Test Case 2
    Input: [1, 2, 3], [4, 5, 6]
    Expected: 5.196152422706632
    Test Case 3
    Input: [0, 0], [0, 0]
    Expected: 0.0
    + 2 hidden test cases