Left never passes right in a window
Updated
After shrink, L ≤ R+1. Empty is L = R+1 (equivalently R < L). L may equal R (one cell). L must not jump to R+2 and leave a hole of un-excluded cells.
What to focus on
Stop shrinking when the window is already empty, or when you still need the one remaining cell. Passing empty (L > R+1) desyncs state from [L,R].
Worked examples
meet at one cell
a = [4, 1, 9], L=2 R=2- L == R
- window is [9]
- next shrink would make empty, not L=4
Result: L=2 R=2 legal
empty is L = R+1
a = [4, 1, 9], L=3 R=2- L = R+1
- no cell remains
- do not L++ again to 4
Result: empty · L=3 R=2
one-cell empty
a = [7], L=0 R=0 then shrink once- exclude 7
- L += 1 → 1
- R stays 0 so L = R+1
Result: empty · L=1 R=0
Try it
Write assertBounds(L, R). L is the left index. R is the right index. Empty is L = R+1. One-cell is L == R. Reject L > R+1. Print legal or reject. Return nothing. On [4, 1, 9] at (2, 2) and (3, 2); [7] shrink from (0, 0) to (1, 0).
a is nonempty. L and R come from expand/shrink so L ≤ R+1.