#C3469. Maximum Difference in Array
Maximum Difference in Array
Maximum Difference in Array
You are given an array of unique integers. Your task is to find the maximum difference between any two elements in the array such that the larger element appears after the smaller one.
Mathematically, given an array A of length N, find the maximum value of \(A[j] - A[i]\) for all \(0 \le i < j < N\). If the array has less than two elements, the output should be 0.
For example, if the input array is [2, 3, 10, 6, 4, 8, 1], the maximum difference is 8 (obtained from 10 - 2).
inputFormat
The first line contains an integer \(N\), representing the number of elements in the array. The second line contains \(N\) space-separated integers.
outputFormat
Output a single integer representing the maximum difference, where the larger number appears after the smaller number. If no valid pair exists, output 0.
## sample7
2 3 10 6 4 8 1
8
</p>