# 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](/wiki/freesoftware/algorithm/two_pointer_technique.md).

## Sliding Window Code Template

```python
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](https://leetcode.com/problems/max-consecutive-ones/) [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/) [Remove Element](https://leetcode.com/problems/remove-element/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aisuko.gitbook.io/wiki/freesoftware/algorithm/sliding_window_technique.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
