Bird
0
0

Consider this pseudocode for per-user rate limiting:

medium📝 Predict Output Q5 of 15
Rest API - Rate Limiting and Throttling
Consider this pseudocode for per-user rate limiting:
requests = {"alice": 2, "bob": 5}
limit = 5
user = "bob"
if requests[user] >= limit:
    print("Limit reached")
else:
    print("Request allowed")

What will be printed?
ANo output
BLimit reached
CError: user not found
DRequest allowed
Step-by-Step Solution
Solution:
  1. Step 1: Check requests count for user

    requests["bob"] is 5, which is equal to limit 5.
  2. Step 2: Evaluate condition and output

    Since requests[user] >= limit is true, it prints "Limit reached".
  3. Final Answer:

    Limit reached -> Option B
  4. Quick Check:

    requests[user] >= limit = True, output = Limit reached [OK]
Quick Trick: Use >= to check if limit reached [OK]
Common Mistakes:
  • Using > instead of >= causing off-by-one errors
  • Confusing user keys
  • Ignoring equality condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes