Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 8 minutes. Part of the Pro drill bank.
Replace each None with the closest earlier value; leading Nones stay None. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement ffill(values: list) -> list that returns a new list where every None is replaced by the most recent earlier value that is not None. Nones before the first real value stay None. Real values such as 0, False and "" are values and must be kept and used for filling. The input list must not change.
Input: ffill([0, None, 5, None]) Output: [0, 0, 5, 5] 0 is a real value, so the None after it becomes 0; the last None takes 5.
Topics: lakebench, python, fill, none, list.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Replace each None with the closest earlier value; leading Nones stay None.
Implement `ffill(values: list) -> list` that returns a new list where every `None` is replaced by the most recent earlier value that is not `None`. Nones before the first real value stay `None`. Real values such as `0`, `False` and `""` are values and must be kept and used for filling. The input list must not change.