Two Pointers & Sliding Windows Flashcards
1
Q
How does the two-pointer technique work?
A
Uses two indices to optimize searching.
2
Q
What are common two-pointer use cases?
A
Sorted Two Sum, Reverse String.
3
Q
What is Sliding Window?
A
Shrinks and expands a window for optimization.
4
Q
What is the difference between fixed and variable sliding windows?
A
Fixed has a set size; variable expands/contracts.
4
Q
A
5
Q
How do we keep sliding window O(n)?
A
The left and right pointers should only traverse the array once.
6
Q
What operations happen in a variable size sliding window?
A
Each element is processed twice: once when expanding, once when contracting.
7
Q
What operations happen in a fixed-size sliding window?
A
Each element is added to the window once and removed once.