> For the complete documentation index, see [llms.txt](https://hao-fu-1.gitbook.io/oj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hao-fu-1.gitbook.io/oj/multiple-pointers/sliding-window/dynamic-window.md).

# Dynamic Window

和静态窗口一样每次向右移动一格，不同的是窗口不是定长的，窗口起始不一定也要往右移动。

实际上它的思想和DP string的题在构造f时有异曲同工の妙，在这里是以一段以r结尾子字符串\[l, r]判断是否满足给定的性质。

这时分为两种题型，分别是求longest substring和shortest substring。

l维持不动，r++直到满足基本条件，但l和r之间可能有超过条件的，这时l++直到刚好满足条件.

因此核心是

1. 知道窗口内元素应是什么性质，
2. 给定判断窗口内元素是否满足该性质的条件。不满足意味着要维持/增加窗口长度，否则就增加/维持窗口长度。

多用于解决Longest substring ...注意是substring不是sub sequence, 前者是必须连着，后者不要求连续。

不适用于对顺序有要求的找min window subsequence.
