dp
with -1 to indicate that no value has been computed yet.getProfit
that takes the current index and returns the maximum profit from that index onwards.getProfit
, if the current index is out of bounds, return 0.dp
at the current index is not -1, return it as the maximum profit has already been computed.dp
at the current index.getProfit(offers, offers.size(), 0)
.