from typing import Sequence


def subdivide_list(li: Sequence, max_size: int) -> list:
    """
    Expands a sorted list of values by repeatedly subdividing the intervals
    in the initial list, stopping before max_size is exceeded.  This keeps
    the originally specified values in position.

    Parameters
    ----------
    li : list or array-like
        Starting values.
    max_size : int
        Upper limit on len(list).

    Returns
    -------
    li_dense : list
        New list containing subdivided values.
    """
    li_dense, li_add = list(li), []
    while len(li_add) + len(li_dense) <= max_size:
        li_dense += li_add
        li_dense.sort()
        li_add = [0.5 * (x1 + x2) for x1, x2 in zip(li_dense, li_dense[1:])]
    return li_dense