Shrinking windows need non-negative values
transcript
Count windows with a total of at most two. Use a shrinking window. Does it always work?
Take the usage three, minus two and one. The shrinking pass counts three windows. But five windows have a total of at most two.
The pass assumes dropping lowers the total. A negative value breaks that. The pass stops too early.
Read the statement for the value range. Look for the words never negative. If they are missing, use another method.
A hundred thousand values have five billion windows. A pass of two pointers visits each value twice.
Name what the pass assumes. Try a tiny counterexample by hand. Then run a slow twin on random lists.
A shrinking window needs non-negative values. Other tools do not need that. Prefix sums work with any values, at a higher price.
Windows need non-negative values. Test a tiny negative case. Full breakdown in the lecture.