prices[i] is the price of a stock on day i. You may buy on one day and sell on a later day, once. Return the largest profit you can make, or 0 if every possible trade loses money (or there are fewer than two days).
The starter code tries every pair of days. It is correct but too slow for long lists. Make it fast.
Example 1
Input:
stock_best_profit([7, 1, 5, 3, 6, 4])
Output:
5
Buy at 1, sell at 6 for a profit of 5.
Example 2
Input:
stock_best_profit([7, 6, 4, 3, 1])
Output:
0
The price only falls, so the best is not to trade: 0.
0 <= len(prices) <= 2 * 10**50 <= prices[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.