#C9549. Maximum Single Transaction Profit
Maximum Single Transaction Profit
Maximum Single Transaction Profit
You are given the daily prices of a stock. Your task is to compute the maximum profit that can be achieved from a single buy-sell transaction. If no profit can be made, output 0.
Formally, given a sequence of prices \(p_1, p_2, \ldots, p_n\), find the maximum value of \(p_j - p_i\) for any indices \(1 \le i < j \le n\). If no such pair exists or if all differences are negative, return 0.
inputFormat
The first line contains a single integer \(n\) which is 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 achievable from one transaction. If no profit is possible, output 0.
## sample6
7 1 5 3 6 4
5
</p>