Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Rest API - Rate Limiting and Throttling
What will be the output of this code snippet?
data = [1, 3, 5, 7]
window_size = 2
max_sums = []
for i in range(len(data) - window_size + 1):
    max_sums.append(max(data[i:i+window_size]))
print(max_sums)
A[3, 5, 7]
B[1, 3, 5]
C[4, 8, 12]
D[7, 7, 7]
Step-by-Step Solution
Solution:
  1. Step 1: Identify sliding windows and their max values

    Windows: [1,3], max=3; [3,5], max=5; [5,7], max=7.
  2. Step 2: Collect max values in list

    max_sums = [3, 5, 7], matching [3, 5, 7].
  3. Final Answer:

    [3, 5, 7] -> Option A
  4. Quick Check:

    Max per window = [3, 5, 7] [OK]
Quick Trick: Use max() on each window slice [OK]
Common Mistakes:
  • Summing instead of taking max
  • Wrong window slices or indices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes