Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Sliding Window Lab
Arrays
Problem shape
Intermediate
4
8
15
16
23
42
Core idea
Maintain a moving window and update its state as the boundary changes.
Step 1 / 5
Problem shape
Arrays Intermediate
Sliding Window
Welcome to the Sliding Window algorithm lab. Maintain a moving window and update its state as the boundary changes. Use it when: Use for subarray, substring, max/min length, and fixed-size window problems. The time complexity is O(n), and the space complexity is O(1) to O(k). The pseudocode is: left = 0 for right from 0 to n - 1 add a[right] to window while window is invalid remove a[left] left++ As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n)
Space
O(1) to O(k)
Pseudocode
left = 0
for right from 0 to n - 1
add a[right] to window
while window is invalid
remove a[left]
left++ 1.0x