🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Sliding Window Quiz: all 8 questions

Sliding Window Quiz · Question 2 of 8

A fixed window of size k slides one step right. How is the new sum computed in O(1)?

A fixed window of size k slides one step right. How is the new sum computed in O(1)?

  1. A.Re-add all k elements
  2. B.Add the new element, subtract the one that left
  3. C.Multiply the old sum by k
  4. D.Sort the window
Answer & explanation

Correct answer: Add the new element, subtract the one that left

Only two elements change, so update the sum incrementally.

Can you get the rest right without peeking?

Take the timed Sliding Window Quiz quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →