Skip to content

prefix / suffix [terminology]

Terminology

Usage

  • Use for accumulations strictly before or after the current position.
  • They communicate direction and excluded boundaries.
res = [1] * n
prefix = 1
for i in range(n):
    res[i] = prefix
    prefix *= nums[i]
suffix = 1
for i in range(n - 1, -1, -1):
    res[i] *= suffix
    suffix *= nums[i]

See 238. Product of Array Except Self.