def max_profit(prices): buy = 0 sell = 1 maxprofit = 0 while sell < len(prices): currentprofit = prices[sell] - prices[buy] if prices[buy] < prices[sell]: maxprofit = max(currentprofit, maxprofit) else: buy = sell sell += 1 return maxprofit # Driver code def main(): prices = [ [1, 2, 4, 2, 5, 7, 2, 4, 9, 0, 9], [8, 2, 6, 4, 7, 5], [7, 6, 4, 3, 1], [2, 6, 8, 7, 8, 7, 9, 4, 1, 2, 4, 5, 8], [1, 2] ] for i in range(len(prices)): print(i + 1, ". Stock prices = ", prices[i], sep="") print(" Maximum profit = ", max_profit(prices[i]), sep="") print("-" * 100) if __name__ == "__main__": main()