Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-171

Linear Interpolation of Missing Points

Problem

Fill missing (None) entries by linear interpolation between the nearest known neighbors; leading and trailing gaps take the nearest known value. Return the completed list.

If every entry is missing, return a list of zeros of the same length.

Hint

Interpolate by the fraction of the distance between the bounding known points.

Test cases

case 1
in: [[1,null,3]]
expected: [1,2,3]
case 2
in: [[null,2,null,4]]
expected: [2,2,3,4]
case 3
in: [[1,2,3]]
expected: [1,2,3]
case 4
in: [[null,null]]
expected: [0,0]
Starter codePython
def linear_interpolation_missing(series):
    # Your code here
    pass

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