Skip to content
DeepForgeby svx
All problems
HardTime Seriests-089

DTW Distance Small

Problem

Compute the dynamic time warping distance between two series using absolute difference cost and the recurrence D[i][j] = |x[i-1] - y[j-1]| + min(D[i-1][j], D[i][j-1], D[i-1][j-1]).

Return the final accumulated cost, or 0.0 if either series is empty.

Hint

DTW can stretch or compress the time axis, so warped series still match cheaply.

Test cases

case 1
in: [[1,2,3],[1,2,3]]
expected: 0
case 2
in: [[1,2,3],[2,2,2]]
expected: 2
case 3
in: [[1,2,3],[1,3]]
expected: 1
case 4
in: [[1,2],[1,2,3]]
expected: 1
Starter codePython
def dtw_distance(x, y):
    # Your code here
    pass

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