Manhattan Distance

EasyMachine LearningMath

Description

Given two equal-length points a and b, return the Manhattan (L1) distance, the sum of absolute coordinate differences.

Examples

Input:a = [0,0], b = [3,4]
Output:7
Explanation:

Summing the absolute coordinate differences gives 7.

Input:a = [1,1], b = [1,1]
Output:0
Explanation:

Summing the absolute coordinate differences gives 0.

Input:a = [1,2,3], b = [4,6,8]
Output:12
Explanation:

Summing the absolute coordinate differences gives 12.

Constraints

  • 1 ≤ a.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.