Home › Interview Questions › How would you design a solution to populate blank …

How would you design a solution to populate blank records in a dataset? Provide a function that back‑populates the missing values.

🟡 Medium Coding Junior level
1Times asked
Oct 2026Last seen
Oct 2026First seen

💡 Model Answer

A simple and efficient way to back‑populate blank records is to iterate through the dataset once, keeping track of the last non‑blank value. In Python, this can be done with a list comprehension or a for‑loop. Complexity is O(n) time and O(1) extra space. Example:

def back_populate(values):
    last = None
    result = []
    for v in values:
        if v is None or v == "":
            result.append(last)
        else:
            last = v
            result.append(v)
    return result

If the blanks should be filled with a forward‑fill or backward‑fill strategy, you can adjust the logic accordingly. For large dataframes, use pandas fillna(method='ffill') or bfill. This approach ensures that every blank record receives the most recent known value, preserving data continuity.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500