MEDIUMasked at 1 company

Change Null Values in a Table to the Previous Value

A medium-tier problem at 52% community acceptance, tagged with Database. Reported in interviews at Deloitte and 0 others.

Founder's read

You're staring at a table with null values scattered throughout a column, and you need to fill them with the last non-null value you saw. This is a real problem Deloitte has asked. The trap is thinking you can do this in a single WHERE clause or a simple UPDATE. You can't. You need window functions to track the running non-null value, and most candidates freeze on that pattern during the live assessment. With a 51% acceptance rate, half the people get this wrong under pressure. StealthCoder surfaces the window function solution instantly if you blank mid-interview, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
52%

Companies that ask "Change Null Values in a Table to the Previous Value"

If this hits your live OA

Change Null Values in a Table to the Previous Value is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The core trick is using a window function to assign a group ID based on when nulls change, then window again to fill forward. Most people try a self-join or a correlated subquery and hit performance walls or logic errors. The standard pattern uses ROW_NUMBER() or SUM() with a CASE statement to create groups of nulls, then LAST_VALUE() or a similar aggregate to fill down. The real gotcha: you must specify your window frame correctly (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), or your fill-forward won't work as expected. SQL dialects vary slightly on window frame syntax, which trips people up in the moment. If you haven't drilled this exact pattern before, StealthCoder is the hedge for the live OA when you're running out of time and your first approach fails.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Change Null Values in a Table to the Previous Value recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Change Null Values in a Table to the Previous Value interview FAQ

Is this still asked at companies beyond Deloitte?+

Input data shows Deloitte as the primary named asker. It's a window-function problem, so it appears in any company's database round where they test medium SQL. Not everywhere, but window functions in general are standard FAANG interview material.

What's the trick to filling nulls forward without a loop?+

Use a window function to assign a group ID based on non-null transitions, then apply LAST_VALUE() or MAX() over that group. Most candidates think a self-join will work, but it's slow and error-prone. Window functions are the pattern here.

Why is the acceptance rate only 51%?+

Window frame syntax is easy to get wrong, and the grouping logic isn't obvious. Many candidates write a query that runs but returns incorrect results. The gap between 'runs' and 'correct' is where the 49% fails.

How does this relate to other window function problems?+

It's a medium-difficulty application of ROW_NUMBER() and aggregate windows. If you've mastered running totals and ranking, the concept is familiar. The new piece is using window logic to identify and group nulls, not just rank rows.

Should I memorize the exact window frame syntax?+

No. Understand the idea: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW means 'from the start to where I am now.' That mental model transfers across dialects. Syntax details you look up during the live assessment.

Want the actual problem statement? View "Change Null Values in a Table to the Previous Value" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.