A segment, not a selection
Positive costs [3,1,2,5,1], target 7.
Find the shortest contiguous qualifying segment.
What does enumerating every start and end repeat?
1 / 10
Positive costs [3,1,2,5,1], target 7.
Find the shortest contiguous qualifying segment.
What does enumerating every start and end repeat?
At right=3: sum 11, length 4.
Remove 3: sum 8, length 3.
Remove 1: sum 7, length 2.
Why never revisit those discarded starts?
At the last element of [2,3,1,2,4,3]:
[2,4,3] sum 9 → length 3
[4,3] sum 7 → length 2
[3] sum 3 → stop
Left boundaries: 0,0,2,2.
At the last a, its previous index 0 is already outside the window.
Why is assigning left=1 wrong?
Target AAC; candidate AC.
Distinct letters agree. Multiplicities do not.
When should formed decrease as an A leaves?
Empty pattern:
CheckInclusion → true
FindAnagrams → all boundaries
MinWindow → empty result
AABABBA, k=1 → best length 4.
A retained window may need more than one replacement after maxFreq becomes stale.
The proof concerns when the best length can grow.
Text xbarfoo, words [bar,foo]
Word length 3; valid start 1.
Run offsets 0,1,2, not only offset 0.
N text bytes, L-byte words.
O(N) token-map operations across offsets do not imply O(N) byte work when L varies.
Hashing a token can inspect L bytes.
Choose state, entering update, leaving update, validity direction, and recording moment.
Then name the condition that lets left move only forward.