Longest Stretch of GPU Power Samples Within a Budget

Last updated: November 29, 2026

Quick Overview

Given a list of non-negative per-interval power readings from a GPU and a budget B, find the length and start index of the longest contiguous stretch whose total energy is at most B.

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

0

0

0 solved


Given a list of non-negative per-interval power readings from a GPU and a budget B, find the length and start index of the longest contiguous stretch whose total energy is at most B.

Shows up in screens for NVIDIA system software and power-management teams that work on DVFS and data center power capping. The interviewer wants a sliding window, a clear argument for why non-negative values make it valid, and awareness that negative values would break it.

What the Interviewer Expects
  • Recognizes the sliding window pattern because readings are non-negative
  • Maintains the window sum incrementally and shrinks from the left
  • Returns both length and start index, with a sentinel for no valid window
  • Explains O(n) total time since each index enters and leaves once
  • Notes that negative values would require prefix sums plus a monotonic structure
Key Topics to Cover
sliding window
two pointers
prefix sums
streaming
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
  • What changes if readings can be negative, for example net energy with regenerative credit?
  • How would you answer this for many different budgets over the same array?
  • How would you adapt it to a live stream of readings where the window must end at the latest sample?
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: power, a list of non-negative integers, and budget. Find the longest subarray with sum at most budget. Return (length, start); if every single reading exceeds the budget, return `(0, -1...

High-Level Design

Two pointers left and right. Extend right one step at a time, adding to a running total. While the total exceeds the budget, subtract power[left] and advance left. Because all values are non...


Submit Your Answer
Markdown supported

Related Questions