Sliding Window Technique

Sliding Window Technique is a method for finding subarray or substring of a given array or string in linear time O(n) by using two pointers technique.

Sliding Window Code Template

def sliding_window(s):
    left, right = 0, 0
    while right < len(s):
        # increase right pointer
        right += 1
        # update window
        ...
        while window needs shrink:
            # increase left pointer
            left += 1
            # update window
            ...

Sliding Window Technique Problems

Max Consecutive Ones Minimum Size Subarray Sum Remove Element

Last updated