#C12274. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given a sequence of stock prices for consecutive days. Your task is to determine the maximum profit that can be made by buying one share of the stock on one day and selling it on a later day.
The profit is calculated as $$profit = price_{sell} - price_{buy}$$ where \(price_{buy}\) is the price on the day you buy and \(price_{sell}\) is the price on the day you sell. If no profit can be achieved, output 0.
inputFormat
The first line contains an integer \(n\) representing the number of days.
The second line contains \(n\) space-separated integers representing the stock prices on each day.
outputFormat
Output a single integer — the maximum profit possible from one transaction. If no profitable transaction exists, output 0.
## sample6
7 1 5 3 6 4
5