🎙 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 7 of 8

Why does a sum-based sliding window fail when the array contains negative numbers?

Why does a sum-based sliding window fail when the array contains negative numbers?

  1. A.Growing the window can make the sum smaller, so "shrink when too big" stops being reliable
  2. B.Negative numbers cannot be stored in a window
  3. C.The window length becomes negative
  4. D.It doesn't fail — it works the same
Answer & explanation

Correct answer: Growing the window can make the sum smaller, so "shrink when too big" stops being reliable

The technique relies on the condition changing in one direction as the window grows. Use prefix sums + hash map instead.

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 →