We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The logic is that you start from the back, setting that as the highest value. THen you move back through the days. If the stock on that day is lower, then you know that it would make sense to buy it, to sell on the higher day... therefore your profit is the difference. If the stock on tht day is higher, then you wouldn't sell AND you have a new highest stock price.
Stock Maximize
You are viewing a single comment's thread. Return to all comments →
Python 3
The logic is that you start from the back, setting that as the highest value. THen you move back through the days. If the stock on that day is lower, then you know that it would make sense to buy it, to sell on the higher day... therefore your profit is the difference. If the stock on tht day is higher, then you wouldn't sell AND you have a new highest stock price.
Super simple and helpful explanation :)