0
0
Rest APIprogramming~20 mins

Sliding window algorithm in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sliding Window Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of sliding window sum calculation
What is the output of this REST API response when calculating the sum of every 3 consecutive numbers in the list?
Rest API
numbers = [1, 3, 5, 7, 9]
window_size = 3
result = []
for i in range(len(numbers) - window_size + 1):
    window_sum = sum(numbers[i:i+window_size])
    result.append(window_sum)
print(result)
A[3, 5, 7]
B[1, 3, 5, 7, 9]
C[15, 21, 27]
D[9, 15, 21]
Attempts:
2 left
💡 Hint
Think about how many sums you get when sliding a window of size 3 over 5 numbers.
🧠 Conceptual
intermediate
1:30remaining
Sliding window algorithm main advantage
What is the main advantage of using a sliding window algorithm over a naive approach when processing sequences?
AIt reduces time complexity by avoiding repeated calculations.
BIt uses more memory to store all intermediate results.
CIt always produces exact results without approximation.
DIt requires sorting the input data first.
Attempts:
2 left
💡 Hint
Think about how sliding windows reuse previous computations.
🔧 Debug
advanced
2:30remaining
Identify the error in sliding window max calculation
This code tries to find the maximum value in every sliding window of size 2 but produces wrong output. What is the error?
Rest API
nums = [4, 2, 12, 3]
window = 2
max_values = []
for i in range(len(nums) - window):
    max_values.append(max(nums[i:i+window]))
print(max_values)
AThe window size variable is not defined before the loop.
BThe max function is used incorrectly; it should be min instead.
CThe loop range should be len(nums) - window + 1 to include the last window.
DThe slice nums[i:i+window] should be nums[i:i+window-1].
Attempts:
2 left
💡 Hint
Check how many windows the loop covers compared to the input length.
📝 Syntax
advanced
2:00remaining
Syntax error in sliding window average calculation
Which option contains the correct syntax to calculate the average of every sliding window of size 4 in a list?
Rest API
data = [10, 20, 30, 40, 50, 60]
window_size = 4
averages = []
for i in range(len(data) - window_size + 1):
    avg = sum(data[i:i+window_size]) / window_size
    averages.append(avg)
print(averages)
A
for i in range(len(data) - window_size + 1): avg = sum(data[i:i+window_size]) / window_size
averages.append(avg)
Bfor i in range(len(data) - window_size + 1): avg = sum(data[i:i+window_size]) / window_size; averages.append(avg)
C)gva(dneppa.segareva ezis_wodniw / )]ezis_wodniw+i:i[atad(mus = gva :)1 + ezis_wodniw - )atad(nel(egnar ni i rof
Dfor i in range(len(data) - window_size + 1): avg = sum(data[i:i+window_size]) / window_size averages.append(avg)
Attempts:
2 left
💡 Hint
Check for proper line breaks or statement separators in Python loops.
🚀 Application
expert
3:00remaining
Sliding window for longest substring without repeating characters
Given the string 'abcabcbb', what is the length of the longest substring without repeating characters using a sliding window approach?
A4
B3
C2
D5
Attempts:
2 left
💡 Hint
Try to find the longest substring where no character repeats by moving the window.