Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Variable-Size Window

The expand → repair → record template
step 1 / 24
4
2
1
1
1
3
5
[0][1][2][3][4][5][6]
Concept
1// the variable-window template
2l ← 0; best ← 0
3for r ← 0 to n − 1:
4 window absorbs arr[r] // expand
5 while invariant broken: // here: sum ≤ 8
6 window drops arr[l]; l++ // contract
7 best = max(best, r − l + 1) // record
8return best
state
  • n7

line 1Fixed windows slide; VARIABLE windows breathe. R always moves right absorbing elements; L moves right only to FIX the window when a rule breaks. That rule is called the INVARIANT.