🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Prefix Sums and Difference Arrays: all 13 questions

Quiz: Prefix Sums and Difference Arrays · Question 3 of 13

Why can't a sliding window count subarrays with sum k when the array has negative numbers?

Why can't a sliding window count subarrays with sum k when the array has negative numbers?

  1. A.Sliding windows only work on strings
  2. B.Shrinking the window no longer always lowers the sum, so the window can't decide which way to move
  3. C.Negative numbers can't be added
  4. D.It can, with no changes
Answer & explanation

Correct answer: Shrinking the window no longer always lowers the sum, so the window can't decide which way to move

The window relies on "grow increases the sum, shrink decreases it", which only holds for positive values.

Can you get the rest right without peeking?

Take the timed Quiz: Prefix Sums and Difference Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →