Checking every substring or subarray is O(n²), and large inputs will time out. A sliding window keeps one contiguous stretch and moves its two ends forward, so each element enters and leaves only once. Use it when the question says "longest" or "shortest" contiguous part with some rule, like no repeated character. If the parts need not be contiguous, a window is the wrong idea, and you usually want DP or hashing instead.