Leaves Remaining After Wind Gusts
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The OpenAI OA reported in September 2026 looks like a simulation problem, and that's the trap. Moving every leaf for each of up to 200000 gusts will time out on a 200 by 200 grid. The real question is which original cells ever fall off the edge, and the answer depends only on the extremes the gust path reaches. If you've got an invite and 48 hours, learn this one idea. StealthCoder is there as a quiet safety net if the edge case slips away mid-assessment, but the logic is short enough to own.
The problem
A rectangular garden is represented by garden. The value garden[r][c] is the number of leaves initially in cell (r, c). Process every character of gusts from left to right. A gust shifts all leaves that are still present by one cell: U: one row up D: one row down L: one column left R: one column right Leaves shifted outside the garden disappear permanently. Return the total number of leaves remaining after all gusts. Function remainingLeafSum(garden: int[][], gusts: String) → long Examples Example 1 garden = [[1,2,3],[4,5,6]] gusts = "R" return = 12 The rightmost column leaves the garden. The surviving original values are 1, 2, 4, and 5. Example 2 garden = [[1,2],[3,4]] gusts = "UD" return = 7 The upward gust permanently removes the first row. The following downward gust cannot restore it, so only values 3 and 4 remain. Example 3 garden = [[5]] gusts = "L" return = 0 The only leaves move beyond the left boundary. Constraints 1 ≤ garden.length, garden[r].length ≤ 200 Every row has the same length. 0 ≤ garden[r][c] ≤ 10^9 0 ≤ gusts.length ≤ 200000 gusts contains only U, D, L, and R.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Don't simulate the leaves. Every leaf moves by the same offset, so track the running row and column displacement as you read the gusts. Record the minimum and maximum of each. A leaf at (r, c) survives only if r + minRow >= 0, r + maxRow < rows, c + minCol >= 0, and c + maxCol < cols. Once a leaf crosses the boundary at any point, it's gone, even if later gusts push it back. That's the pitfall in Example 2: UD is not a no-op. The surviving cells form a rectangle, so sum it with a double loop (40000 cells) or prefix sums. Use a 64-bit long, since 40000 times 10^9 overflows int. Empty gusts means the whole grid survives. If the extremes remove every row or column, return 0. Total work is O(gusts + rows*cols). If you blank on the extremes idea, StealthCoder can surface it live.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Leaves Remaining After Wind Gusts cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass OpenAI's OA.
OpenAI reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Leaves Remaining After Wind Gusts FAQ
How hard is Leaves Remaining After Wind Gusts really?+
Easy to medium. The code is short, but the naive per-gust simulation fails on 200000 gusts. If you spot that every leaf shares one displacement, it's a 15-minute problem. The difficulty is the insight, not the implementation.
What's the trick?+
Track the cumulative offset and its min and max in both axes. A cell survives only if it stays inside the grid at the extreme offsets. Leaves that leave the grid never return, so the extremes decide survival, not the final position.
Why does Example 2 return 7 and not 10?+
The U gust pushes the first row out of the garden, and those leaves disappear permanently. The D gust moves the remaining rows back, but nothing returns the lost row. Only 3 and 4 survive, so the sum is 7.
What edge cases should I test?+
Empty gusts, which keeps everything. A single cell grid with any move, which gives 0. Gusts like UD or LR that cancel out but still delete cells. Values up to 10^9 summed over 40000 cells, which needs a long.
How do I prepare for this in 48 hours?+
Write the min/max offset solution once from scratch and run the three examples. Then practice similar grid shift and boundary problems. Spend the rest of the time on overflow checks and the empty input case, since those are where this one breaks.