A Palantir Foundry pipeline receives daily prices for one stock. Starting with initial_cash, maximize the cash value at the end of the period by making any number of buy and sell transactions.
You may hold at most one share at a time, cannot short-sell, and may buy or sell at most once per day. A fixed fee is deducted whenever a share is sold. You may make no transactions. Return the maximum possible final cash value after processing all prices.
Implement max_final_value(prices, initial_cash, fee), where prices is a list of nonnegative integers, and initial_cash and fee are nonnegative integers. Return an integer representing the maximum final cash after optionally liquidating any held share on the final day.
def max_final_value(prices, initial_cash, fee):