A sliding window is a range of the list, from left to right, that you keep summarized as it moves: a running total, a count of failures, the last position of each character. Moving an edge updates that summary in constant time, so you never add up the same items twice.
A fixed window of k items adds the item that enters and subtracts the one that leaves. A variable window grows its right edge one item at a time and shrinks from the left while it breaks a rule (a repeated character, too many failures), or while it still meets a goal (the shortest span that reaches a total).
Both edges only move forward, so each item enters and leaves once: O(n) time, with O(1) extra space for a total or O(k) for a map. Shrinking needs the summary to move one way as the window grows. Negative values break "shrink while the total is big enough". Test an empty list, a window as long as the list, all negative values and a window that ends on the last item.
sales = [4, -1, 6, 2, -3, 5], days = 3
first window [4, -1, 6] total 9 best 9
add 2, drop 4 -> [-1, 6, 2] total 7 best 9
add -3, drop -1 -> [6, 2, -3] total 5 best 9
add 5, drop 6 -> [2, -3, 5] total 4 best 9
answer: 9, with one addition and one subtraction per slide
Each slide changes the total by the day that enters minus the day that leaves, so no window is added up from scratch.