#K80632. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given (n) stock prices where the (i)-th element represents the price of the stock on day (i). You are allowed to complete at most one transaction (i.e., buy one and sell one share of the stock). Your task is to determine the maximum profit you can achieve from this transaction. Note that you must buy before you sell. If it is impossible to obtain any profit, return 0.
inputFormat
The input consists of two lines. The first line contains an integer (n), indicating the number of days. The second line contains (n) space-separated integers which represent the stock prices for each day.
outputFormat
Output a single integer representing the maximum profit possible. If no profit is achievable, output 0.## sample
6
7 1 5 3 6 4
5