Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Forward-fill None

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.

Requirements

  • Return a new list of the same length.

Constraints

  • Values can be any type.
  • The input is not modified.

Examples

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

beginner

Forward-fill None

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.