Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-144

Forward-Fill vs Back-Fill Difference

Problem

Count the positions where forward filling and backward filling disagree. Forward fill carries the last known value downward (leading gaps seed from the first known value); backward fill carries the next known value upward (trailing gaps seed from the last known value).

Return the number of positions where the two filled series differ, or 0 if the series has no known values.

Hint

A gap disagrees when its two ends have different values.

Test cases

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

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