Bird
0
0

Given a stream of API request sizes arriving continuously, how can the sliding window algorithm help in monitoring the average request size over the last 5 requests efficiently?

hard📝 Application Q9 of 15
Rest API - Rate Limiting and Throttling
Given a stream of API request sizes arriving continuously, how can the sliding window algorithm help in monitoring the average request size over the last 5 requests efficiently?
ABy storing all requests indefinitely and averaging them all
BBy recalculating the sum of all 5 requests every time a new request arrives
CBy maintaining a running sum and updating it as the window slides forward
DBy ignoring the oldest requests and only averaging new ones
Step-by-Step Solution
Solution:
  1. Step 1: Understand efficient sliding window monitoring

    Maintaining a running sum allows updating the average by subtracting the oldest and adding the newest request size.
  2. Step 2: Avoid recalculating sum from scratch each time

    Recalculating sum every time is inefficient; running sum is optimal.
  3. Final Answer:

    By maintaining a running sum and updating it as the window slides forward -> Option C
  4. Quick Check:

    Running sum updates = efficient sliding window [OK]
Quick Trick: Use running sum to update averages efficiently [OK]
Common Mistakes:
  • Recalculating sums fully each time
  • Ignoring oldest data in window

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes