The "Change Null Values in a Table to the Previous Value interview question" is a SQL/Database challenge often called "Forward Fill" or "Last Observation Carried Forward" (LOCF). You are given a table where some rows have NULL values in a specific column. You need to replace each NULL with the value from the most recent non-null row (based on a chronological ID or timestamp).
Deloitte and other data-heavy firms ask the "Change Null Values in a Table coding problem" because it is a common data cleaning requirement in time-series analysis. It tests your knowledge of Window Functions and the ability to create synthetic grouping keys. It evaluations your understanding of how to process records in a specific order while maintaining state across rows.
This problem typically uses Window Functions and a Two-Pass Grouping pattern.
NULLs share the same group ID.FIRST_VALUE() or a similar function to propagate the non-null value to the entire group.id or timestamp) to define the "previous" relationship.Table: (1, 'A'), (2, NULL), (3, NULL), (4, 'B'), (5, NULL)
(1, 'A'), (2, 'A'), (3, 'A'), (4, 'B'), (5, 'B').ORDER BY clause in the window function, which makes the result non-deterministic.Master the OVER (ORDER BY ...) clause in SQL. Understanding how to use cumulative counts to "partition" data into islands of related records is a powerful "Database interview pattern" skill.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Nth Highest Salary | Medium | Solve | |
| Managers with at Least 5 Direct Reports | Medium | Solve | |
| Second Highest Salary | Medium | Solve | |
| Active Businesses | Medium | Solve | |
| Active Users | Medium | Solve |