Bird
Raised Fist0

Which of the following is the correct way to check the current window start time in a fixed window algorithm using Python?

easy📝 Syntax Q12 of Q15
Rest API - Rate Limiting and Throttling

Which of the following is the correct way to check the current window start time in a fixed window algorithm using Python?

import time
window_size = 60  # seconds
current_time = int(time.time())
window_start = ?
Acurrent_time - (current_time % window_size)
Bcurrent_time % window_size
Ccurrent_time + window_size
Dwindow_size - current_time
Step-by-Step Solution
Solution:
  1. Step 1: Calculate window start using modulo

    The window start is the current time minus the remainder when divided by window size, to align to window boundary.
  2. Step 2: Apply formula

    Using current_time - (current_time % window_size) gives the start of the current fixed window.
  3. Final Answer:

    current_time - (current_time % window_size) -> Option A
  4. Quick Check:

    Window start = current_time - remainder [OK]
Quick Trick: Use modulo to find window start time [OK]
Common Mistakes:
MISTAKES
  • Using modulo alone without subtraction
  • Adding window size instead of subtracting remainder
  • Confusing window start with window end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes