Skip to content

w / r [terminology]

Terminology

Usage

  • Use w for a write index and r for a read index in compact in-place algorithms.
  • w marks where the next retained value is written.
  • r marks the element currently being inspected.
  • This pair is preferable to generic i and j because it expresses data flow.
w = 0

for r in range(n):
    if nums[r] != 0:
        nums[w], nums[r] = nums[r], nums[w]
        w += 1