Rolling Peak GPU Memory Over the Last K Training Steps

Last updated: November 29, 2026

Quick Overview

Given the GPU memory used at each training step and a window size k, return the maximum memory over every window of k consecutive steps, in linear time.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given the GPU memory used at each training step and a window size k, return the maximum memory over every window of k consecutive steps, in linear time.

Training dashboards at OpenAI watch peak memory over recent steps to catch leaks and fragmentation before an out-of-memory crash takes down a large job. This is a sliding window maximum, and the interviewer wants the monotonic deque solution with a clear invariant, not a heap or a rescan of each window.

What the Interviewer Expects
  • Identify that a naive rescan is O(nk)
  • Maintain a deque of indices with decreasing values
  • Pop dominated entries from the back and expired ones from the front
  • State the invariant and amortized O(1) per step
  • Compare with a heap with lazy deletion
Key Topics to Cover
monotonic queue
sliding window maximum
deque
streaming metrics
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Report the rolling minimum and maximum together.
  • The window is defined by time (last 60 seconds) instead of step count: what changes?
  • Emit an alert when the rolling peak grows for 100 consecutive windows.
  • Compute this for 10,000 GPUs streaming at once.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of integers memory and window size k >= 1.
  • Output: list of length n - k + 1 where entry j is max(memory[j : j + k]).
  • If n < k, return an empty list....
High-Level Design

Keep a deque of indices whose values strictly decrease from front to back. When a new value arrives, pop from the back every index whose value is less than or equal to it: those entries are older and ...


Submit Your Answer
Markdown supported