awelgorithms

Name the left edge of a window

Updated

L is the leftmost index in the window. It is an index, not a value. a[L] is the cell sitting at that index.

What to focus on

L is inclusive. Every index < L is outside. L is not a[L].

Worked examples

left of a middle window

a = [4, 1, 9, 1], L=1 R=3
  1. left edge is index 1
  2. a[1] = 1
  3. index 0 is outside

Result: L = 1

left of the whole array

a = [4, 1, 9], L=0 R=2
  1. left edge is index 0
  2. a[0] = 4

Result: L = 0

left of a string window

s = "abca", L=2 R=3
  1. left edge is index 2
  2. s[2] = c

Result: L = 2

Try it

Write leftEdge(L, R). L is the left index of the window. R is the right index. The window includes a[L] through a[R]. L is inclusive. Return L. Do not confuse L with a[L]. On a=[4, 1, 9, 1] with (1, 3) and (0, 3); a=[4, 1, 9] with (0, 2); s="abca" with (2, 3).

a (or s) is nonempty. 0 ≤ L ≤ R < n.