#K62867. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given a series of daily stock prices. Your task is to determine the maximum profit that can be made by buying the stock on one day and selling it on a later day. If no profit is possible, then the answer should be 0.
Mathematically, if the prices on day \(i\) and day \(j\) are \(p_i\) and \(p_j\) (with \(j > i\)), then the profit is \(p_j - p_i\). The goal is to maximize this value.
inputFormat
The first line of input contains an integer \(n\), the number of days. The second line contains \(n\) space-separated integers representing the stock prices on consecutive days.
outputFormat
Output a single integer that represents the maximum profit achievable. If no profit can be made, output \(0\).
## sample6
7 1 5 3 6 4
5