0
0
Rest APIprogramming~10 mins

Fixed window algorithm in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the fixed window counter dictionary.

Rest API
counters = [1]
Drag options to blanks, or click blank then click option'
Aset()
B[]
C{}
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or set instead of a dictionary.
2fill in blank
medium

Complete the code to get the current timestamp in seconds.

Rest API
current_time = int(time.[1]())
Drag options to blanks, or click blank then click option'
Asleep
Btime
Cctime
Dlocaltime
Attempts:
3 left
💡 Hint
Common Mistakes
Using ctime() which returns a string, not a timestamp.
3fill in blank
hard

Fix the error in the condition that resets the window when the time window has passed.

Rest API
if current_time - counters[client_id]['start_time'] [1] window_size:
Drag options to blanks, or click blank then click option'
A<
B<=
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or == which do not cover the full window expiration condition.
4fill in blank
hard

Fill both blanks to update the counter and reset the start time when the window expires.

Rest API
counters[client_id]['count'] = [1]
counters[client_id]['start_time'] = [2]
Drag options to blanks, or click blank then click option'
A1
Bcurrent_time
C0
Dwindow_size
Attempts:
3 left
💡 Hint
Common Mistakes
Resetting count to 0 instead of 1, or not updating start time.
5fill in blank
hard

Fill all three blanks to increment the count, check if the request is allowed, and return the correct boolean.

Rest API
counters[client_id]['count'] [1] 1
if counters[client_id]['count'] [2] max_requests:
    return [3]
else:
    return True
Drag options to blanks, or click blank then click option'
A+=
B>
CFalse
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the condition or returning True when blocking is needed.