Longest Stable Quote Window Within a Price Band
Last updated: November 29, 2026
Quick Overview
Given a sequence of tick prices for one instrument and a tolerance k, find the longest contiguous run of ticks whose maximum minus minimum is at most k, and return its length and indices.
Akuna Capital
November 29, 20260
0
0 solved
Given a sequence of tick prices for one instrument and a tolerance k, find the longest contiguous run of ticks whose maximum minus minimum is at most k, and return its length and indices.
This fits the HackerRank style online assessment Akuna Capital uses early in its software engineering loop, framed around market data. The grader wants an O(n) sliding window with monotonic deques rather than a quadratic scan, and clean handling of window shrinking.
What the Interviewer Expects
- Recognize a variable sliding window where validity depends on max and min
- Maintain max and min in O(1) amortized with two monotonic deques
- Shrink from the left only while the window is invalid
- Return both length and indices for the best window
- Handle empty input and k = 0
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 answer the same query for many different k values?
- What changes if ticks arrive as a stream and you need the current longest window ending now?
- How would you use a time-based window (last 500 ms) instead of a count?
- Could you do this with a sorted container, and what would it cost?
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 k >= 0. Output: length of the longest window with max - min <= k, plus the (left, right) indices of one such window. Empty input returns 0....
High-Level Design
Two pointers define the window. Expanding right is always allowed; if the spread then exceeds k, advance left until valid. The only hard part is knowing max and min of the current window quickly. ...