# Minimum Window Subsequence (Practice 5058): Pattern

Interviewers use this pattern to test whether you can state the invariant before coding. Here is a compact rehearsal note.

## Approach

Two-pointer forward scan to match `t` inside `s`, then walk backward to shrink the window start.

```python
def min_window(s,t):
best=(0,10**9);i=0
while i j=0
while i if s[i]==t[j]:
j+=1
if j==len(t): break
i+=1
if i==len(s): break
end=i;j-=1
while j>=0:
if s[i]==t[j]: j-=1
i-=1
i+=1
if end-i i+=1
return '' if best[1]==10**9 else s[best[0]:best[1]+1]
```

## Complexity

Linear in the dominant input size for the scan; heap/tree variants add a log factor.

## Interview pitfalls

State the invariant out loud, name the complexity, then code. Skipping the invariant is the usual fail mode.

## Practicing out loud

Narrate the approach, complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see Linkjob AI copilot.
Published with deed.pageReport abuse