When should you reach for the sliding window technique, and what makes a problem a good fit?
The sliding window technique fits problems where you want the best answer over a contiguous range of an array or string, and where you can maintain a running summary of that range as it moves. The two ingredients are a window, which is a range of the input, and an efficient way to update the summary when the window shifts by one position on either side.
A good fit usually has three properties. There is a natural window size, either fixed as in a maximum sum of k consecutive elements or variable as in the longest substring without repeated characters. Adding a character to the window and removing one from it can both be done in constant time, usually through a counter or a running sum. And the answer can be read off the window summary at each step without recomputing anything.
The technique exists to avoid the nested loop. A brute force approach tries every starting position and scans forward, which is quadratic. The sliding window reuses the work done for the previous window: when the window moves one step, one element leaves and one arrives, and you update the summary accordingly rather than starting over.
The trade-off to name is that the window technique needs an invertible or incremental summary. If removing an element from the window requires rescanning the window, the technique buys nothing. A running sum works because subtraction undoes addition. A maximum does not work in the same way, because you cannot un-set the maximum, which is why the maximum sliding window problem needs a monotonic deque instead. Recognising which of the two you are dealing with is the real skill here, and it is a question interviewers ask precisely to see whether you understand the constraint rather than memorising a template.