Flag Price Breakouts Above a Trailing K Tick High
Last updated: November 29, 2026
Quick Overview
Given a list of prices and a window k, return every index i (with i >= k) where the price is strictly greater than the maximum of the previous k prices, in O(n) time.
D. E. Shaw
November 29, 20260
0
0 solved
Given a list of prices and a window k, return every index i (with i >= k) where the price is strictly greater than the maximum of the previous k prices, in O(n) time.
A phone screen problem in the style of D. E. Shaw, framed as a building block for a momentum signal computed over long tick histories. The interviewer wants the monotonic deque, a correct definition of the window that excludes the current tick, and a proof that the work is linear.
What the Interviewer Expects
- Notes that the window is the previous k ticks and excludes the current one
- Uses a monotonic decreasing deque of indices
- Checks the breakout before inserting the current price
- Argues O(n) amortized because each index is pushed and popped at most once
- Compares to the O(nk) brute force and uses it to test
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 report breakouts below the trailing low at the same time?
- How do you adapt this to a time-based window (last 5 seconds) with irregular ticks?
- How would you vectorize this over thousands of symbols in a research notebook?
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: prices p[0..n-1], integer k >= 1. Output: indices i >= k with p[i] > max(p[i-k..i-1]). Equal to the prior high is not a breakout. Should run in a single pass so it also works on a strea...
High-Level Design
Maintain a deque of indices whose prices are strictly decreasing from front to back. The front is the maximum of the current trailing window. At each step: evict indices older than i - k, compare `p...