Two Pointers & Sliding Windows Flashcards

1
Q

How does the two-pointer technique work?

A

Uses two indices to optimize searching.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are common two-pointer use cases?

A

Sorted Two Sum, Reverse String.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Sliding Window?

A

Shrinks and expands a window for optimization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between fixed and variable sliding windows?

A

Fixed has a set size; variable expands/contracts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we keep sliding window O(n)?

A

The left and right pointers should only traverse the array once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What operations happen in a variable size sliding window?

A

Each element is processed twice: once when expanding, once when contracting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What operations happen in a fixed-size sliding window?

A

Each element is added to the window once and removed once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly