#C8612. Maximum Stock Trading Profit
Maximum Stock Trading Profit
Maximum Stock Trading Profit
You are given a sequence of stock prices, where the i-th price represents the stock price on day \(i\). Your task is to compute the maximum profit that can be achieved by buying one share of the stock and then selling it on a later day. If no profit can be achieved, output \(0\).
The profit is defined as \(\text{profit} = \text{prices}_j - \text{prices}_i\) for \(i < j\). Ensure that you buy before you sell.
inputFormat
The first line contains an integer (n) representing the number of days. The second line contains (n) space-separated integers denoting the stock prices.
outputFormat
Output a single integer representing the maximum profit. If no profit can be made, output (0).## sample
6
7 1 5 3 6 4
5
</p>