Coding Pattern:
Sliding Window
This pattern has an earnable cheat sheet.
Pattern concept
Step 1 of 21
Use ← → arrow keys
Code snippets
How to identify
Does the problem involve any of these?
- Finding a contiguous subarray or substring that fulfills certain requirements
- Shortest Length Subarray Sum: Subarray that has a certain sum.
- Longest Substring Without Repeats: Substring that has no repeats.
- Fruit into Basket: Longest subarray with two distinct elements.
- Minimum Window Substring: Shortest substring that contains all characters in another string.
Note
Most sliding window problems can be solved in O(n) time since they can be solved efficiently by updating the window instead of recomputing all elements.