free
to 0 and hold
to -prices[0]
.i
, perform the following steps:
a. Store the current value of hold
in a temporary variable tmp
.
b. Update hold
to the maximum of hold
and free - prices[i]
.
c. Update free
to the maximum of free
and tmp + prices[i] - fee
.free
as it represents the maximum profit achievable without holding any stock.