#K75277. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given a list of stock prices where the price on the i-th day is given by (p_i). Your task is to determine the maximum profit achievable by performing exactly one buy and one sell operation. Note that the buy action must occur before the sell action, so you are to find indices (i) and (j) such that (i < j) and the profit (p_j - p_i) is maximized. If no profit can be made, output 0.
inputFormat
The first line contains a single integer (n) representing the number of days. The second line contains (n) space-separated integers (p_1, p_2, \dots, p_n) indicating the stock prices for each day.
outputFormat
Output a single integer representing the maximum profit that can be achieved. If no profit is possible, output 0.## sample
6
7 1 5 3 6 4
5