Skip to content

lo / hi [terminology]

Terminology

Usage

  • Use for lower and upper bounds in a value domain.
  • They are especially useful for binary search over possible answers rather than array positions.
  • They may represent values that do not directly index a collection.
lo, hi = matrix[0][0], matrix[-1][-1]
while lo < hi:
    mid = (lo + hi) // 2
    # cnt = ...
    if cnt < k:
        lo = mid + 1
    else:
        hi = mid
return lo

See 378. Kth Smallest Element in a Sorted Matrix.