Longest Trading Window Where Price Range Stays Within Band

Last updated: November 29, 2026

Quick Overview

Given a list of trade prices in time order and a limit L, return the length of the longest contiguous window whose maximum price minus minimum price is at most L.

Point72
Coding & Algorithms
Software Engineer
Point72
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Given a list of trade prices in time order and a limit L, return the length of the longest contiguous window whose maximum price minus minimum price is at most L.

Point72 online assessments often wrap classic window problems in market data, here a volatility band used to flag calm regimes for execution algorithms. The grader expects an O(n) solution, so the interviewer is checking whether the candidate knows to maintain window max and min with monotonic deques instead of rescanning.

What the Interviewer Expects
  • Recognize a variable-size sliding window with a validity condition on max minus min
  • Maintain a decreasing deque for the max and an increasing deque for the min
  • Shrink from the left while the band is violated and pop stale indices
  • Achieve O(n) time with each index pushed and popped at most once
  • Handle equal prices and an empty input
Key Topics to Cover
sliding window
monotonic deque
two pointers
streaming max and min
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
  • How would you return the start and end timestamps of the window instead of its length?
  • Prices arrive as a live stream: how do you report the current valid window after each tick?
  • Change the condition to a percentage band relative to the window minimum: does the approach still work?
  • How would you do this with a time-based window, say at most 60 seconds long?
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

Prices are in time order. We want the longest contiguous run where max minus min is at most L. Output is a length; zero for an empty list. Brute force over all windows is O(n^2) or worse, and the asse...

High-Level Design

Use two pointers. Extend the right edge one tick at a time. Keep a deque of indices with decreasing prices so the front is the window max, and a deque with increasing prices so the front is the window...


Submit Your Answer
Markdown supported