Algorithm · Amazon · Medium
Suppose you have a historical record of daily stock prices for a particular company, stored in an array prices of size n. prices[i] tells you the price of one share on day i. You are given a trading mode flag mode and a transaction fee fee. Your goal is to determine the maximum profit you can earn by buying and selling shares according to the rules described below. If mode = 1, you are allowed to perform at most one complete transaction – that is, you may buy on one day and…