I’m confused about how the backward phase in the code works if it’s calculating the maximum profit if we buy on day i, instead of calculating the maximum profit if we buy on OR AFTER day i.

<12,11,13,9,12,8,14,13,15>

For example, if i = 6, the max profit would be whatever profit we calculated from the first subarray + (15-14) = 1, instead of first subarray profit + (15-13)=2.

maxPriceSoFar = Math.max(maxPriceSoFar, prices.get(i));

maxTotalProfit = Math.max(

maxTotalProfit,

maxPriceSoFar - prices.get(i) + firstBuySellProfits.get(i - 1));

Thanks!