Skip to content
C

Best Time to Buy and Sell Stock

Easyjavapythonccppjavascript

Given daily stock prices, choose one day to buy and a later day to sell so that the profit is as large as possible.

Input Format

The first line contains an integer N. The second line contains N space-separated integers, where the i-th value is the price on day i.

Output Format

Print the maximum possible profit, or 0 if no profit can be made.

Input (stdin)

Output

Run your code to see output here...