def trim_solver_results(problem, recommended_solns, intermediate_budgets):
    """
    Trim solutions recommended by solver after problem's max budget.

    Arguments
    ---------
    problem : base.Problem object
        Problem object on which the solver was run
    recommended_solutions : list of base.Solution objects
        solutions recommended by the solver
    intermediate_budgets : list of ints >= 0
        intermediate budgets at which solver recommended different solutions
    """
    # Remove solutions corresponding to intermediate budgets exceeding max budget.
    invalid_idxs = [idx for idx, element in enumerate(intermediate_budgets) if element > problem.factors["budget"]]
    for invalid_idx in sorted(invalid_idxs, reverse=True):
        del recommended_solns[invalid_idx]
        del intermediate_budgets[invalid_idx]
    # If no solution is recommended at the final budget,
    # re-recommend the latest recommended solution.
    # (Necessary for clean plotting of progress curves.)
    if intermediate_budgets[-1] < problem.factors["budget"]:
        recommended_solns.append(recommended_solns[-1])
        intermediate_budgets.append(problem.factors["budget"])
    return recommended_solns, intermediate_budgets