Divide and Conquer
Given an array A, write a program to find the max(A[j]-A[i])
where i < j
. If max(A[j]-A[i])<0
, output 0. The input will start with
an integer n, which indicates the length of the given array. The next
line will be the array.
Please try to use divide and conquer. No for or while loops unless in min or max over an array. Your algorithm needs to be O(n log n) to pass
Example 1
Input:
2
1 5
Output:
4
Example 2:
Input:
4
1 5 8 2
Output:
7
Example 3:
Input:
6
8 7 4 3 2 1
Output:
0