awelgorithms

Window over an empty sequence

Updated

If a is empty, n = 0 and there is no legal index. The only window is empty: L = 0, R = -1 (R < L).

What to focus on

Do not name L=0 R=0 on n=0 — index 0 does not exist. Expand is illegal because R+1 < n fails. Empty sequence ⇒ empty window only. This skill is that n = 0 case.

Worked examples

only empty

a = []
  1. n = 0
  2. L=0 R=-1
  3. no index is in range

Result: empty window · L=0 R=-1

reject one-cell

a = [], refuse L=0 R=0
  1. R=0 would claim index 0
  2. n=0 has no slot 0

Result: illegal · stay L=0 R=-1

string empty

s = ""
  1. n = 0
  2. same sentinel R=-1
  3. no character to include

Result: empty window · L=0 R=-1

Try it

Write windowOn(a). a is an empty array, or s is an empty string. n = 0. L is 0. R is -1. There is no cell in the window. Print (L, R) = (0, -1). Prove (0, 0) is rejected. Return nothing. Run on a=[] and s="".

a (or s) is empty. n = 0.