Patterns

Concept shape

Practice pattern
0
1
2
3
4
5
Definition

Maintain a window over a sequence and update state as the window moves.

Step 1 / 5
Concept shape
Current lesson

Sliding Window Pattern Lab

Patterns Practice pattern

Sliding Window Pattern

Welcome to the Sliding Window Pattern concept lab. Maintain a window over a sequence and update state as the window moves. The must know points are: Fixed window has constant-size movement. Variable window grows and shrinks. Often used for substrings and subarrays. The common operations are: expand right, shrink left, update window state. The complexity shape is Usually O(n). Watch out for these pitfalls: Shrinking too late or too early. Not updating state when left moves. Related algorithms include Longest Substring Without Repeating Characters, Max Sum Subarray.

Concept details

Maintain a window over a sequence and update state as the window moves.

Must know

  • Fixed window has constant-size movement.
  • Variable window grows and shrinks.
  • Often used for substrings and subarrays.

Complexity

Usually O(n)

Open deeper visual structure lesson
1.0x