题目描述
Given an unsorted array Arr of length N. Your task is to find the maximum difference between the successive elements in its sorted form.
Return 0 if the array contains less than 2 elements.
Example 1:
Input:
N = 3
Arr[] = {1, 10, 5}
Output: 5
Explanation: The maximum difference
between successive elements of array
is 5(abs(5-10)).
Your Task:
Complete the function maxSortedAdjacentDiff() which takes array arr and size n, as input parameters and returns an integer representing the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{6}
1 ≤ Arr[i] ≤ 10^{6}
输入格式
见题面
输出格式
见题面
样例输入
N = 3
Arr[] = {1, 10, 5}
样例输出
5