Peak Requests Per Second Over a Sparse Rolling Window

Last updated: November 29, 2026

Quick Overview

API traffic is recorded as time-sorted samples `(second, request_count)`, with missing seconds meaning zero requests. For every sample, return the maximum count seen in the window of the last `k` seconds ending at that sample.

Stripe
Coding & Algorithms
Software Engineer
Stripe
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


API traffic is recorded as time-sorted samples `(second, request_count)`, with missing seconds meaning zero requests. For every sample, return the maximum count seen in the window of the last `k` seconds ending at that sample.

Stripe tracks per-account API load to tune rate limits and spot integration bugs that hammer the API. The samples are sparse because most accounts are quiet most seconds, so the interviewer checks that you apply a monotonic deque keyed by time rather than by index, and that you can explain the amortized cost.

What the Interviewer Expects
  • Use a deque of samples with strictly decreasing counts
  • Expire from the front by timestamp (`second <= t - k`), not by position
  • Pop from the back while the back's count is not larger than the new count
  • Explain why each sample is pushed and popped at most once
  • Point out that sparseness does not break correctness because the current sample is always in its own window
Key Topics to Cover
monotonic deque
sliding window
streams
rate limiting
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 minimum or the median as well?
  • How would you handle samples that arrive slightly out of order?
  • What changes if you need these maxima for a million accounts at once?
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: list of (second, count) with strictly increasing seconds, and window length k >= 1. The window for a sample at second t is (t - k, t]. Output: a list of maxima, one per sample....

High-Level Design

Maintain a deque of (second, count) whose counts strictly decrease from front to back. For each new sample, first drop front entries whose second is outside the window, then drop back entries with c...


Submit Your Answer
Markdown supported