Skip to content

start / end [terminology]

Terminology

Usage

  • Use for meaningful boundaries of an interval, substring, slice, or run.
  • Prefer them when the boundaries describe a region rather than active left and right pointers.
  • They are clearer when stored, returned, or used during backtracking.
is_palindrome = [[False] * n for _ in range(n)]
# A substring is a palindrome when its ends match and its
# interior is empty, one character, or already a palindrome.
for start in range(n - 1, -1, -1):
    for end in range(start, n):
        is_palindrome[start][end] = (
            s[start] == s[end]
            and (
                end - start <= 2
                or is_palindrome[start + 1][end - 1]
            )
        )

See 131. Palindrome Partitioning.