Loading section...
Spotting the Pattern
Concepts: pySlidingWindow, pyPatternRecognition
The distinction between sliding window and other patterns comes down to one word: contiguous. If the problem asks about a contiguous subarray or substring, sliding window is on the table. If it asks about a subsequence (elements do not need to be adjacent), sliding window is the wrong tool. This is the most common misidentification. Candidates try to slide a window on a subsequence problem and waste 15 minutes before realizing the approach does not work. Read the problem statement carefully. 'Subarray' and 'substring' mean contiguous. 'Subsequence' does not. The second signal is a constraint on the window. 'Find the maximum sum of K consecutive elements.' 'Find the longest substring with at most K distinct characters.' 'Find the shortest subarray with sum >= target.' The constraint defines