Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-004

Lag-k Series

Problem

Return the lag-k series, i.e. the values x[t-k] for t = k, ..., n-1. The result is the original series shifted down by k positions and is therefore k elements shorter.

Return an empty list if k is negative or k is not smaller than the series length; k = 0 returns a copy of the series.

Hint

The first k output values are the first n - k inputs.

Test cases

case 1
in: [[1,2,3,4],1]
expected: [1,2,3]
case 2
in: [[1,2,3,4],2]
expected: [1,2]
case 3
in: [[1,2,3],3]
expected: []
case 4
in: [[9,8,7,6,5],0]
expected: [9,8,7,6,5]
Starter codePython
def lag_series(series, k):
    # Your code here
    pass

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