Bird
0
0

Given the following Python code snippet implementing a fixed window rate limiter, what will be the output?

medium📝 Predict Output Q13 of 15
Rest API - Rate Limiting and Throttling

Given the following Python code snippet implementing a fixed window rate limiter, what will be the output?

requests = [1, 1, 1, 1, 1]
limit = 3
window_start = 0
count = 0
for req in requests:
    if count < limit:
        count += req
        print("Allowed")
    else:
        print("Blocked")
AAllowed Allowed Allowed Allowed Allowed
BBlocked Blocked Blocked Blocked Blocked
CAllowed Allowed Allowed Blocked Blocked
DAllowed Allowed Blocked Allowed Blocked
Step-by-Step Solution
Solution:
  1. Step 1: Trace request counts

    Count starts at 0. For each request (value 1), count increases until it reaches limit 3.
  2. Step 2: Determine allowed or blocked

    First 3 requests increase count to 3 and print "Allowed". Next requests exceed limit, so print "Blocked".
  3. Final Answer:

    Allowed Allowed Allowed Blocked Blocked -> Option C
  4. Quick Check:

    Count ≤ 3 allowed, else blocked [OK]
Quick Trick: Count requests and block after limit reached [OK]
Common Mistakes:
  • Assuming all requests allowed
  • Resetting count incorrectly
  • Confusing count comparison operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes