Sliding Window Cheat Sheet
Quick reference for coding interviews. Bookmark this page!
What is Sliding Window?
Optimize subarray and substring problems with the sliding window pattern.
Trigger Words
When you see these in a problem, think Sliding Window:
Template Code
def maxProfit(prices: List[int]) -> int:
min_price = float('inf')
max_profit = 0
for price in prices:
min_price = min(min_price, price)
profit = price - min_price
max_profit = max(max_profit, profit)
return max_profit
Complexity
| Typical Time | O(n) |
|---|---|
| Typical Space | O(1) |
Common Variations
- Basic Sliding Window
- Sliding Window with constraints
- Optimized Sliding Window
Practice Problems
See all Sliding Window problems →Practice Sliding Window
Learn to recognize patterns instantly with interactive MCQs.
Download LeetEye Free