Practice · 1 of 3
The Re-added Window
CHALLENGE
Difficulty: advanced+25 XP
**Scenario.** Code computes, for every window of size k, the window's sum by looping k elements: O(nk) with n = 200000, k = 1000. What is the fix? **Which approach is the best fit? The program only needs to print the letter.** **A)** Rewrite the inner loop in assembly **B)** Sliding window: maintain a running sum, add the entering element, subtract the leaving one — O(n) **C)** Sort the array first **D)** Use a segment tree over the array
Press Submit to check your solution.
Back to lesson: Practice: Optimization Drills