We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
The window grows from the right until it violates a constraint, then shrinks from the left until it is valid again - each element enters and leaves at most once, giving O(n). The word contiguous in a problem statement is the giveaway. Variable-size windows (longest substring without repeats) and fixed-size windows (max sum of k elements) are the two shapes worth drilling until they are automatic.
"Longest/shortest contiguous subarray or substring satisfying X."
9 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.