G6 · Pupil · 8 min

Window Snake

A row of positive numbers and a budget k. Expand R to include the next cell, or advance L to drop the left cell. The live sum is the payload. Hit a window whose length is the longest with sum ≤ k. The invariant bar tells you which pointer should move — hide it when you are ready.

k · sum budget

8

need length

4

payload · sum

2

L/R2
11
25
32
43
52
61
74

window [0, 0] · length 1 · legal

Legal → R++ (include)