Longest Latency Window Where Max Minus Min Stays Within Limit

Last updated: November 29, 2026

Quick Overview

Given request latencies in time order and a limit, return the length of the longest contiguous window whose maximum minus minimum latency is at most the limit.

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

0

0

0 solved


Given request latencies in time order and a limit, return the length of the longest contiguous window whose maximum minus minimum latency is at most the limit.

Asked at Meta in technical screens with a production-monitoring framing: finding the longest stable stretch of a service's p50 latency. The interviewer wants a sliding window that tracks both extremes in O(1) amortized with two monotonic deques rather than a sorted structure.

What the Interviewer Expects
  • Use a two-pointer sliding window that only grows or shifts
  • Maintain a decreasing deque for the max and an increasing deque for the min
  • Shrink from the left when max - min exceeds the limit
  • Evict deque fronts that leave the window
  • Compare with a sorted-container O(n log n) alternative
Key Topics to Cover
Monotonic deque
Sliding window
Two pointers
Monitoring
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
  • Return the start and end index of the window as well.
  • Count all windows that satisfy the limit.
  • How would you do this over a stream with a fixed memory budget?
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 lat of integers and integer limit >= 0. Output: the maximum j - i + 1 such that max(lat[i..j]) - min(lat[i..j]) <= limit. Non-empty input always has an answer of at least 1....

High-Level Design

Expand the right edge one step at a time. Keep maxq, indices with strictly decreasing latency, and minq, indices with strictly increasing latency; their fronts are the window max and min. When add...


Submit Your Answer
Markdown supported