Longest Calm Price Window Within a Tick Tolerance
Last updated: November 29, 2026
Quick Overview
Given a series of mid prices and a tolerance, find the longest contiguous window in which the maximum price minus the minimum price never exceeds the tolerance, returning its length and start index.
DRW
November 29, 20260
0
0 solved
Given a series of mid prices and a tolerance, find the longest contiguous window in which the maximum price minus the minimum price never exceeds the tolerance, returning its length and start index.
Researchers and developers at DRW work with tick data constantly, and finding regimes where price stays pinned is a realistic preprocessing step. The question tests sliding windows combined with monotonic deques, and the interviewer wants the O(n) solution, not a sorted structure or brute force.
What the Interviewer Expects
- Explains why a two pointer window is valid (shrinking never helps a window that already fails)
- Maintains a decreasing deque for max and increasing deque for min
- Advances left and evicts stale indices correctly
- Achieves O(n) time with amortized argument
- Handles empty input and zero tolerance
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
- How would you solve it with a balanced BST or sorted container, and what does that cost?
- Return every maximal calm window instead of the longest one.
- Make it streaming: report the current calm window length on every tick.
- How would you adapt it to a time based window of at most T seconds?
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 of prices (floats or integer ticks) and a tolerance tol >= 0. Output: (length, start) of the longest window with max - min <= tol, earliest on ties. Empty input gives (0, 0)....
High-Level Design
If a window [l, r] violates the tolerance, every window [l, r'] with r' > r also violates it, so left only moves forward. We need the window max and min in O(1): keep two deques of indices, on...