Longest Stable Sensor Window Where Max Minus Min Stays Within a Limit
Last updated: November 29, 2026
Quick Overview
Given a stream of readings from a Nest thermostat and a tolerance, return the length of the longest contiguous window in which the difference between the maximum and minimum reading is at most the tolerance.
0
0
0 solved
Given a stream of readings from a Nest thermostat and a tolerance, return the length of the longest contiguous window in which the difference between the maximum and minimum reading is at most the tolerance.
A Google onsite sliding window that needs both the running max and the running min, framed around detecting stable periods for Nest temperature learning. The interviewer checks the use of two monotonic deques and correct eviction when the left edge moves.
What the Interviewer Expects
- Keeps a decreasing deque for the max and an increasing deque for the min
- Shrinks the window while max minus min exceeds the tolerance
- Evicts deque fronts only when they equal the leaving element or by index
- Explains amortized O(n)
- Mentions the sorted-container alternative at O(n log n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the window itself, not just its length.
- What if the readings arrive as a stream and you must report the current longest window?
- How would you allow a small fraction of outlier readings inside the window?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list
rof numbers,tol >= 0. - Output: maximum length of a contiguous window with
max - min <= tol....
High-Level Design
Use a variable window. To know its max and min in O(1), keep two deques of indices: hi_q with values decreasing (front is the max) and lo_q with values increasing (front is the min). When adding `...