One Perfect Trade
Given daily prices, buy once and sell later once. Print the maximum profit (0 if no profitable trade exists).
Input: the first line has N; the second line has N prices.
Output: the best single-trade profit.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ pi ≤ 109
Sample Tests
Input 1
6 7 1 5 3 6 4
Output 1
5
Input 2
3 7 6 5
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.