def _coalesce(elems):
    """Sort and coalesce adjacent ranges (in-place).

    Args:
        elems (list): List of 2-tuples (lo, hi).

    Returns:
        list: List `elems` after sorting in-place and coalescing ranges.

    Raises:
        ValueError: Overlapping ranges.
    """
    elems.sort()
    i = 0
    while i < len(elems) - 1:
        (lo0, hi0), (lo1, hi1) = elems[i:i + 2]
        if not lo0 <= hi0 < lo1 <= hi1:
            raise ValueError('Range overlaps at index %d: %r' % (i, elems[i
                :i + 2]))
        if lo1 == hi0 + 1:
            elems[i:i + 2] = [(lo0, hi1)]
        else:
            i += 1
    return elems
