Largest Price Swing Within Any K-Tick Window on Yahoo Finance

Last updated: November 29, 2026

Quick Overview

Given a list of trade prices for a ticker and an integer k, return the largest difference between the maximum and minimum price inside any window of k consecutive ticks. Solve it in linear time.

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

0

0

0 solved


Given a list of trade prices for a ticker and an integer k, return the largest difference between the maximum and minimum price inside any window of k consecutive ticks. Solve it in linear time.

Yahoo Finance shows intraday ranges and volatility on quote pages, so streaming window statistics are a natural coding topic. The interviewer wants to see you move from an O(nk) scan to monotonic deques and reason about why each index is pushed and popped once.

What the Interviewer Expects
  • Start with the brute force and state its O(nk) cost
  • Maintain a decreasing deque for maxima and an increasing deque for minima
  • Evict indices that fall out of the window from the front
  • Explain the amortized O(n) argument
  • Handle k larger than the list and k equal to 1
Key Topics to Cover
sliding window
monotonic deque
amortized analysis
streaming statistics
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 report the window start index along with the swing?
  • How would you adapt this to a time-based window (last 5 minutes) with irregular ticks?
  • Can you do this for a live stream with bounded memory?
  • What if you needed the swing for every window, not just the maximum?
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: prices (list of floats or ints) and k. Output: max over windows of (max(window) - min(window)). If k >= len(prices) treat the whole list as one window; an empty list returns 0....

High-Level Design

Brute force recomputes max and min for each window: O(nk). Instead keep two deques of indices:

  • hi holds indices with strictly decreasing prices, so hi[0] is the window max.
  • lo holds indices ...

Submit Your Answer
Markdown supported

Related Questions