Minkowski Distance
MediumMachine LearningMathSortingTree
Description
Given two equal-length vectors and an order p, return the Minkowski distance: the p-th root of the sum of absolute coordinate differences each raised to the power p. Round the result to 4 decimal places.
Examples
Input:
[0,0], [3,4], 2Output:
5Explanation:
Minkowski generalizes the family of distances, becoming Manhattan at order one and Euclidean at order two.
Input:
[1,2,3], [4,6,8], 1Output:
12Explanation:
Minkowski generalizes the family of distances, becoming Manhattan at order one and Euclidean at order two.
Input:
[0,0], [1,1], 3Output:
1.2599Explanation:
Minkowski generalizes the family of distances, becoming Manhattan at order one and Euclidean at order two.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
1 ≤ p ≤ 5