Throttle Friend Requests With a Per-Sender Sliding Window

Last updated: November 29, 2026

Quick Overview

Given a time-ordered stream of (timestamp, sender_id) friend requests, accept a request only if that sender has had fewer than k accepted requests in the previous w seconds, and return a list of accept or reject decisions.

PlayStation
Coding & Algorithms
Software Engineer
PlayStation
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a time-ordered stream of (timestamp, sender_id) friend requests, accept a request only if that sender has had fewer than k accepted requests in the previous w seconds, and return a list of accept or reject decisions.

PSN friend requests are a common spam and harassment vector, so per-account throttling is a realistic small problem for a social services team. The interviewer looks for a correct sliding window, a clear definition of the window boundary, and awareness that rejected requests should not consume quota.

What the Interviewer Expects
  • Define the window precisely as (t - w, t]
  • Keep a deque of accepted timestamps per sender and evict expired ones
  • Do not count rejected requests toward the limit
  • Explain amortized O(1) per request
  • Discuss memory growth for many idle senders
Key Topics to Cover
Sliding window
Deque
Rate limiting
Hash map
Abuse prevention
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 enforce this across many stateless API servers?
  • How would you clean up deques for senders who stop sending?
  • Would a token bucket be a better fit here, and what behavior would change?
  • How would you add a stricter limit for brand new accounts?
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

Requests arrive sorted by timestamp (ties allowed). For each one, accept if the sender has fewer than k accepted requests with timestamps in (t - w, t]. Rejected requests are not recorded, so a sp...

High-Level Design

Map each sender to a deque of the timestamps of their accepted requests. On a new request, pop from the left while the oldest timestamp is <= t - w. If the deque has fewer than k entries, append a...


Submit Your Answer
Markdown supported

Related Questions