Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-321

Second Differences

Problem

Return the second differences of a series, defined by x[t] - 2 * x[t-1] + x[t-2] for t from 2 onward. This is the result of applying the differencing operator twice and removes a linear trend from the data.

Return an empty list when the series has fewer than three values.

Hint

Second differences are the differences of the first differences.

Test cases

case 1
in: [[1,4,9,16]]
expected: [2,2]
case 2
in: [[1,2,3]]
expected: [0]
case 3
in: [[1,1]]
expected: []
case 4
in: [[5]]
expected: []
Starter codePython
def second_differences(series):
    # Your code here
    pass

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