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}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3
class Solution:

	def maxSortedAdjacentDiff(self,arr, n):
    # code here

Solutions:
class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		max_diff = 0
		for i in range(1, n):
			max_diff = max(max_diff, arr[i] - arr[i - 1])
		return max_diff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		max = 0
		arr.sort()
		for i in range(0, n - 1):
			x = abs(arr[i + 1] - arr[i])
			if x > max:
				max = x
		return max


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		ans = 0
		for i in range(1, n):
			diff = abs(arr[i] - arr[i - 1])
			if diff > ans:
				ans = diff
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr = sorted(arr)
		d = 0
		max = 0
		for i in range(len(arr) - 1):
			d = arr[i + 1] - arr[i]
			if max < d:
				max = d
		return max


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		mx_diff = 0
		for index in range(n - 1):
			diff = abs(arr[index] - arr[index + 1])
			mx_diff = diff if diff > mx_diff else mx_diff
		return mx_diff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		n = max(arr) + 1
		temp = [0] * n
		for i in arr:
			temp[i] = 1
		m = 0
		l = -1
		for i in range(n):
			if temp[i]:
				l = i
				break
		for i in range(l + 1, n):
			if temp[i]:
				m = max(m, i - l)
				l = i
		return m


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		if len(arr) < 2:
			return 0
		else:
			ma = 0
			for i in range(len(arr) - 1):
				if abs(arr[i] - arr[i + 1]) > ma:
					ma = abs(arr[i] - arr[i + 1])
			return ma


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if len(arr) < 2:
			return 0
		else:
			arr = sorted(arr)
			maxdiff = arr[1] - arr[0]
			for i in range(len(arr) - 1):
				diff = arr[i + 1] - arr[i]
				if diff > maxdiff:
					maxdiff = diff
		return maxdiff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		l = []
		if len(arr) == 1:
			return 0
		else:
			for i in range(len(arr) - 1):
				l.append(abs(arr[i] - arr[i + 1]))
			return max(l)


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		d = 0
		for i in range(1, n):
			t = arr[i] - arr[i - 1]
			if t > d:
				d = t
		return d


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		maxi = 0
		for i in range(n - 1):
			maxi = max(maxi, arr[i + 1] - arr[i])
		return maxi


import math

class Solution:

	def get_min_and_max_in_array(self, arr):
		(min_val, max_val) = (math.inf, -math.inf)
		for elem in arr:
			min_val = min(min_val, elem)
			max_val = max(max_val, elem)
		return [min_val, max_val]

	def maxSortedAdjacentDiff(self, arr, n):
		if n == 1:
			return 0
		(min_val_arr, max_val_arr) = ([math.inf] * n, [-math.inf] * n)
		(min_elem, max_elem) = self.get_min_and_max_in_array(arr)
		min_gap_val = (max_elem - min_elem) / (n - 1)
		for elem in arr:
			index = int((elem - min_elem) // min_gap_val)
			min_val_arr[index] = min(min_val_arr[index], elem)
			max_val_arr[index] = max(max_val_arr[index], elem)
		prev_index = ans = 0
		for i in range(n):
			if min_val_arr[i] != math.inf:
				ans = max(ans, min_val_arr[i] - max_val_arr[prev_index])
				prev_index = i
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		N = n
		A = arr
		if N < 2:
			return 0
		if N == 2:
			return abs(A[0] - A[1])
		Min = min(A)
		Max = max(A)
		if Min == Max:
			return 0
		if (Max - Min) % (N - 1) == 0:
			gap = (Max - Min) / (N - 1)
		else:
			gap = (Max - Min) // (N - 1) + 1
		mina = [float('inf') for i in range(N)]
		maxa = [-float('inf') for i in range(N)]
		for i in range(N):
			bkt = int((A[i] - Min) // gap)
			mina[bkt] = min(mina[bkt], A[i])
			maxa[bkt] = max(maxa[bkt], A[i])
		ans = prev = -float('inf')
		for i in range(N):
			if mina[i] == float('inf'):
				continue
			if prev == -float('inf'):
				prev = maxa[i]
			else:
				ans = max(ans, mina[i] - prev)
				prev = maxa[i]
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		maxi = 0
		if n < 2:
			return 0
		else:
			for i in range(n - 1):
				maxi = max(maxi, abs(arr[i] - arr[i + 1]))
		return maxi


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		new_element = 0
		for i in range(1, n):
			count = abs(arr[i - 1] - arr[i])
			if count > new_element:
				new_element = count
		return new_element


import math

class Solution:

	def get_min_and_max_in_array(self, arr):
		(min_val, max_val) = (math.inf, -math.inf)
		for elem in arr:
			min_val = min(min_val, elem)
			max_val = max(max_val, elem)
		return [min_val, max_val]

	def maxSortedAdjacentDiff(self, arr, n):
		if n == 1:
			return 0
		(min_val, max_val) = self.get_min_and_max_in_array(arr)
		min_gap_val = (max_val - min_val) / (n - 1)
		(max_arr, min_arr) = ([-math.inf] * n, [math.inf] * n)
		for i in range(n):
			index = int((arr[i] - min_val) / min_gap_val)
			max_arr[index] = max(arr[i], max_arr[index])
			min_arr[index] = min(arr[i], min_arr[index])
		prev_max_index = 0
		while prev_max_index < n:
			if max_arr[prev_max_index] != -math.inf:
				break
			prev_max_index += 1
		ans = 0
		for i in range(1, n):
			if min_arr[i] == math.inf:
				continue
			ans = max(ans, min_arr[i] - max_arr[prev_max_index])
			while prev_max_index + 1 < n:
				prev_max_index += 1
				if max_arr[prev_max_index] != -math.inf:
					break
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		l = []
		if len(arr) < 2:
			return 0
		arr = sorted(arr)
		for i in range(0, n - 1):
			l.append(abs(arr[i] - arr[i + 1]))
		return max(l)


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		maxm = float('-inf')
		minm = float('inf')
		i = 0
		j = n - 1
		while i <= j:
			maxm = max(maxm, arr[i], arr[j])
			minm = min(minm, arr[i], arr[j])
			i += 1
			j -= 1
		if maxm == minm:
			return 0
		gap = (maxm - minm) // (n - 1)
		if (maxm - minm) % (n - 1) != 0:
			gap += 1
		maxArr = [float('-inf')] * n
		minArr = [float('inf')] * n
		for i in range(n):
			bkt = (arr[i] - minm) // gap
			maxArr[bkt] = max(maxArr[bkt], arr[i])
			minArr[bkt] = min(minArr[bkt], arr[i])
		ans = float('-inf')
		prev = float('-inf')
		for i in range(n):
			if maxArr[i] == float('-inf'):
				continue
			if prev == float('-inf'):
				prev = maxArr[i]
			else:
				ans = max(ans, minArr[i] - prev)
				prev = maxArr[i]
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		if n < 2:
			return 0
		k = []
		for i in range(n - 1):
			k.append(abs(arr[i] - arr[i + 1]))
		return max(k)


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		sum1 = 0
		for i in range(1, n):
			j = i - 1
			sum1 = max(arr[i] - arr[j], sum1)
		return sum1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		if n < 2:
			return 0
		res = 0
		for i in range(n - 1):
			temp = 0
			temp = abs(arr[i] - arr[i + 1])
			if temp > res:
				res = temp
		return res


import heapq

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		a = []
		while arr:
			heapq.heappush(a, arr.pop())
		while a:
			arr.append(heapq.heappop(a))
		c = 0
		pre = None
		for i in arr:
			if pre:
				c = max(abs(pre - i), c)
			pre = i
		return c


import math

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		mini = min(arr)
		maxi = max(arr)
		buckets = math.ceil((maxi - mini) / (n - 1))
		b_mx = [-float('inf')] * (n - 1)
		b_mn = [float('inf')] * (n - 1)
		for i in arr:
			if i == maxi or i == mini:
				continue
			ind = (i - mini) // buckets
			b_mx[ind] = max(b_mx[ind], i)
			b_mn[ind] = min(b_mn[ind], i)
		prev = mini
		maxg = 0
		for i in range(0, n - 1):
			if b_mx[i] == -float('inf'):
				continue
			maxg = max(maxg, b_mn[i] - prev)
			prev = b_mx[i]
		maxg = max(maxg, maxi - prev)
		return maxg


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if len(arr) < 2:
			return 0
		else:
			arr.sort()
			m = 0
			for i in range(1, n):
				m = max(arr[i] - arr[i - 1], m)
			return m


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		minVal = min(arr)
		maxVal = max(arr)
		size = maxVal - minVal + 1
		arrRange = [0] * size
		for val in arr:
			arrRange[val - minVal] += 1
		res = []
		for i in range(size):
			if arrRange[i] > 0:
				for j in range(arrRange[i]):
					res.append(i + minVal)
		maxDiff = -1
		for i in range(len(res) - 1, 0, -1):
			maxDiff = max(maxDiff, res[i] - res[i - 1])
		return maxDiff
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		a = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.maxSortedAdjacentDiff(a, n)
		print(ans)
		tc = tc - 1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		m = 0
		arr = sorted(arr)
		for i in range(n - 1):
			k = abs(arr[i] - arr[i + 1])
			if k > m:
				m = k
		return m
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		a = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.maxSortedAdjacentDiff(a, n)
		print(ans)
		tc = tc - 1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		if len(arr) < 2:
			return 0
		elif len(arr) == 2:
			return abs(arr[0] - arr[1])
		kk = 0
		for i in range(1, len(arr)):
			kk = max(kk, abs(arr[i - 1] - arr[i]))
		return kk
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		a = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.maxSortedAdjacentDiff(a, n)
		print(ans)
		tc = tc - 1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		else:
			m = -1111111111
			arr.sort()
			for i in range(n - 1):
				m = max(m, abs(arr[i] - arr[i + 1]))
			return m
if __name__ == '__main__':
	tc = int(input())
	while tc > 0:
		n = int(input())
		a = list(map(int, input().strip().split()))
		ob = Solution()
		ans = ob.maxSortedAdjacentDiff(a, n)
		print(ans)
		tc = tc - 1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		ans = 0
		for i in range(n - 1):
			a = arr[i + 1] - arr[i]
			if a > ans:
				ans = a
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr = sorted(arr)
		n = len(arr)
		if n < 2:
			return 0
		max_no = -1
		for i in range(1, n):
			diff = abs(arr[i] - arr[i - 1])
			if diff > max_no:
				max_no = diff
		return max_no


class Solution:

	def maxSortedAdjacentDiff(self, Arr, N):
		s = [0] * (max(Arr) + 1)
		for i in range(0, len(Arr)):
			s[Arr[i]] = 1
		isFirst = True
		carryon = -1
		ans = float('-inf')
		for i in range(0, len(s)):
			if isFirst and s[i] == 1:
				carryon = i
				isFirst = False
			elif s[i] == 1:
				ans = max(ans, i - carryon)
				carryon = i
		return ans if ans != float('-inf') else 0


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		(MAX, MIN) = (max(arr), min(arr))
		h = [-1] * (MAX - MIN + 1)
		for e in arr:
			h[e - MIN] = 1
		ans = 0
		prev = -1
		for i in range(0, MAX - MIN + 1):
			if h[i] != -1:
				e = i + MIN
				if prev != -1:
					ans = max(ans, abs(e - prev))
				prev = e
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		if n < 2:
			return 0
		else:
			maxx = -float('inf')
			for i in range(n - 1):
				if abs(arr[i] - arr[i + 1]) > maxx:
					maxx = abs(arr[i] - arr[i + 1])
			return maxx


class Solution:

	def find_max_min(self, arr, n):
		max_num = float('-inf')
		min_num = float('inf')
		for i in range(n):
			if arr[i] > max_num:
				max_num = arr[i]
			if arr[i] < min_num:
				min_num = arr[i]
		return (max_num, min_num)

	def maxSortedAdjacentDiff(self, arr, n):
		if n <= 1:
			return 0
		(max_num, min_num) = self.find_max_min(arr, n)
		range_1 = max_num - min_num + 1
		hole_arr = [0] * range_1
		for i in range(n):
			hole_arr[arr[i] - min_num] = hole_arr[arr[i] - min_num] + 1
		j = 0
		for i in range(range_1):
			while hole_arr[i] > 0:
				hole_arr[i] -= 1
				arr[j] = i + min_num
				j = j + 1
		max_diff = float('-inf')
		for i in range(n - 1, -1, -1):
			if i - 1 >= 0:
				max_diff = max(max_diff, abs(arr[i] - arr[i - 1]))
		return max_diff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		high = max(arr)
		low = min(arr)
		if n < 2 or low == high:
			return 0
		B_min = [float('inf') for _ in range(n)]
		B_max = [float('-inf') for _ in range(n)]
		for i in range(n):
			ind = min((arr[i] - low) * (n - 1) // (high - low), n - 1)
			B_min[ind] = min(B_min[ind], arr[i])
			B_max[ind] = max(B_max[ind], arr[i])
		prev = B_max[0]
		ans = float('-inf')
		for i in range(1, n):
			if B_min[i] != float('inf'):
				ans = max(ans, B_min[i] - prev)
				prev = B_max[i]
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, nums, n):
		if n < 2:
			return 0
		low = min(nums)
		high = max(nums)
		B = {}
		for num in nums:
			if num == high:
				ind = n - 1
			else:
				ind = (num - low) * (n - 1) // (high - low)
			if ind not in B:
				B[ind] = []
			B[ind].append(num)
		buckets = []
		for i in range(n):
			if i in B:
				buckets.append((min(B[i]), max(B[i])))
		ans = 0
		for i in range(1, len(buckets)):
			ans = max(ans, buckets[i][0] - buckets[i - 1][1])
		return ans


import math

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		(maxVal, minVal) = (arr[0], arr[0])
		for i in range(1, n):
			maxVal = max(maxVal, arr[i])
			minVal = min(minVal, arr[i])
		bSize = max(1, (maxVal - minVal) // (n - 1))
		bNum = (maxVal - minVal) // bSize + 1
		INT_MIN = -math.inf
		INT_MAX = math.inf
		maxBucket = [INT_MIN] * bNum
		minBucket = [INT_MAX] * bNum
		for i in range(0, n):
			if arr[i] == maxVal or arr[i] == minVal:
				continue
			index = (arr[i] - minVal) // bSize
			if maxBucket[index] == INT_MIN:
				maxBucket[index] = arr[i]
			else:
				maxBucket[index] = max(maxBucket[index], arr[i])
			if minBucket[index] == INT_MAX:
				minBucket[index] = arr[i]
			else:
				minBucket[index] = min(minBucket[index], arr[i])
		(prev_val, max_gap) = (minVal, 0)
		for i in range(0, bNum):
			if minBucket[i] == INT_MAX:
				continue
			max_gap = max(max_gap, minBucket[i] - prev_val)
			prev_val = maxBucket[i]
		max_gap = max(max_gap, maxVal - prev_val)
		return max_gap


from functools import reduce

class Solution:

	def radix_sort(self, nums):
		num_digits = len(str(max(nums)))
		A = nums
		for i in range(num_digits):
			B = [[] for _ in range(10)]
			for num in A:
				bucket = num // 10 ** i % 10
				B[bucket].append(num)
			A = reduce(lambda x, y: x + y, B)
		return A

	def maximum_Gap(self, sorted_array):
		max_gap = -float('inf')
		for i in range(1, len(sorted_array)):
			if sorted_array[i] - sorted_array[i - 1] >= max_gap:
				max_gap = sorted_array[i] - sorted_array[i - 1]
		return max_gap

	def maxSortedAdjacentDiff(self, nums, n):
		if n < 2:
			return 0
		sorted_array = self.radix_sort(nums)
		max_gap = self.maximum_Gap(sorted_array)
		return max_gap


from sys import maxsize

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		ans = -maxsize
		for i in range(n - 1):
			ans = max(ans, arr[i + 1] - arr[i])
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		diff = 0
		for i in range(1, len(arr)):
			diff = max(diff, arr[i] - arr[i - 1])
		return diff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		maxgap = 0
		if len(arr) < 2:
			return 0
		for i in range(1, len(arr)):
			tmpgap = arr[i] - arr[i - 1]
			if tmpgap > maxgap:
				maxgap = tmpgap
		return maxgap


import math
import sys

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		minele = arr[0]
		maxele = arr[0]
		for i in range(0, n):
			minele = min(minele, arr[i])
			maxele = max(maxele, arr[i])
		interval = math.ceil((maxele - minele) / (n - 1))
		minBuc = [sys.maxsize] * (n - 1)
		maxBuc = [-1] * (n - 1)
		for i in range(n):
			if arr[i] == minele or arr[i] == maxele:
				continue
			index = (arr[i] - minele) // interval
			minBuc[index] = min(arr[i], minBuc[index])
			maxBuc[index] = max(arr[i], maxBuc[index])
		prev = minele
		maxGap = 0
		for i in range(n - 1):
			if maxBuc[i] == -1:
				continue
			maxGap = max(maxGap, minBuc[i] - prev)
			prev = maxBuc[i]
		maxGap = max(maxGap, maxele - prev)
		return maxGap


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		l = self.pegionHole(arr)
		max = 0
		for i in range(n - 1):
			if max < l[i + 1] - l[i]:
				max = l[i + 1] - l[i]
		return max

	def pegionHole(self, arr):
		mini = min(arr)
		maxi = max(arr)
		size = maxi - mini + 1
		holes = [0] * size
		for i in arr:
			holes[i - mini] += 1
		j = 0
		for i in range(size):
			while holes[i] > 0:
				holes[i] -= 1
				arr[j] = i + mini
				j += 1
		return arr


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr = sorted(arr)
		if n < 2:
			return 0
		diff = arr[1] - arr[0]
		for i in range(1, n):
			diff = max(diff, arr[i] - arr[i - 1])
		return diff


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		res = []
		if len(arr) < 2:
			return 0
		else:
			for i in range(len(arr) - 1):
				r = abs(arr[i] - arr[i + 1])
				res.append(r)
		return max(res)


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		prev = arr[0]
		ma = 0
		for i in arr:
			if abs(prev - i) > ma:
				ma = abs(prev - i)
			prev = i
		return ma


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		mi = min(arr)
		ma = max(arr)
		m = ma - mi + 1
		v = [False] * m
		for i in range(n):
			v[arr[i] - mi] = True
		dif = 0
		l = 0
		h = 0
		for i in range(m):
			if v[i]:
				l = h
				h = i
				dif = max(dif, h - l)
		return dif


import heapq

class Solution:

	def find_min_max(self, arr):
		min_ele = 999999999999999
		max_ele = -999999999999999
		for ele in arr:
			if ele > max_ele:
				max_ele = ele
			if ele < min_ele:
				min_ele = ele
		return (min_ele, max_ele)

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		(min_ele, max_ele) = self.find_min_max(arr)
		range_ele = max_ele - min_ele + 1
		pigeon_arr = [0] * range_ele
		for ele in arr:
			pigeon_arr[ele - min_ele] = pigeon_arr[ele - min_ele] + 1
		j = 0
		for i in range(range_ele):
			while pigeon_arr[i] > 0:
				pigeon_arr[i] = pigeon_arr[i] - 1
				arr[j] = i + min_ele
				j = j + 1
		max_diff = 0
		for i in range(n):
			if i - 1 < 0:
				if abs(arr[i] - arr[i + 1]) > abs(max_diff):
					max_diff = abs(arr[i] - arr[i + 1])
			elif i + 1 >= n:
				if abs(arr[i] - arr[i - 1]) > abs(max_diff):
					max_diff = abs(arr[i] - arr[i - 1])
			else:
				if abs(arr[i] - arr[i + 1]) > abs(max_diff):
					max_diff = abs(arr[i] - arr[i + 1])
				if abs(arr[i] - arr[i - 1]) > abs(max_diff):
					max_diff = abs(arr[i] - arr[i - 1])
		return max_diff


import heapq

class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if len(arr) < 2:
			return 0
		heapq.heapify(arr)
		k = heapq.heappop(arr)
		ans = 0
		while arr:
			t = heapq.heappop(arr)
			ans = max(ans, abs(k - t))
			k = t
		return ans


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if len(arr) < 2:
			return 0
		mn = min(arr)
		mx = max(arr)
		if mx == mn:
			return 0
		l = [0 for i in range(mx - mn + 1)]
		for i in arr:
			l[i - mn] += 1
		res = 0
		temp = 0
		for i in l:
			if temp > res:
				res = temp
			if i == 0:
				temp += 1
			else:
				temp = 0
		return res + 1


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		if n < 2:
			return 0
		arr.sort()
		return max([x - y for (x, y) in zip(arr[1:], arr[:-1])])


class Solution:

	def maxSortedAdjacentDiff(self, arr, n):
		arr.sort()
		sm = 0
		for i in range(n - 1):
			d = abs(arr[i] - arr[i + 1])
			if sm < d:
				sm = d
		return sm