def imputed_indices(invalid, length, method='bfill'):
    """Imputation indices assuming the last element is valid.

    Args:
        invalid: List of negative indices of invalid entries.
        length: Length of the list to impute.
        method: Imputation methods. Default 'bfill' implements backward-fill
            (use next valid element to fill the gap).

    Returns:
        indices: indices that give an imputed array.

    Example:
        bad_map = [0, 1, 1, 0, 0, 1, 0]
        invalid = [-2, -5, -6], length = 7
        indices = [0, 3, 3, 3, 4, 6, 6]
    """
    assert method == 'bfill'
    indices = list(range(length))
    for i in range(-2, -length-1, -1):
        if i in invalid:
            indices[i] = indices[i+1]
    return indices