Skip to content

l / r [terminology]

Terminology

Usage

  • Use for moving left and right indices or pointers.
  • Common uses include:
    • Two-pointer scans
    • Sliding windows
    • Binary search over sequence positions
    • Recursive boundaries that move inward
  • Prefer left and right when several directional concepts coexist or the scope is large.
l, r = 0, len(s) - 1
while l < r:
    s[l], s[r] = s[r], s[l]
    l += 1
    r -= 1

See 344. Reverse String.