Sliding Window

Sliding window is useful when a problem asks about a continuous section of an array or string.

When To Use It

Basic Idea

Use two pointers, usually left and right.

left = 0

for right in range(len(items)):
    # expand the window with items[right]

    while window_is_invalid:
        # shrink the window from the left
        left += 1

Common Examples

Original Source