Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-030

Manhattan Distance

Problem

Compute the Manhattan (city-block) distance between two vectors: sum(|a_i - b_i|).

Empty vectors return 0.

Hint

Sum the absolute coordinate differences.

Test cases

case 1
in: [[3,4],[0,0]]
expected: 7
case 2
in: [[1,2,3],[4,5,6]]
expected: 9
case 3
in: [[-1,-1],[2,3]]
expected: 7
case 4
in: [[5],[5]]
expected: 0
Starter codePython
def manhattan_distance(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor