The absolute difference is the positive difference between two values $\boldsymbol{a}$ and $\boldsymbol{b}$, is written $\left|a-b\right|$ or $|b-a|$ and they are equal.  If $\boldsymbol{a}=3$ and $b=2$, $|3-2|=|2-3|=1$. Given an array of integers, find the minimum absolute difference between any two elements in the array.  

Example. 
$arr=[-2,2,4]$ 

There are $3$ pairs of numbers: $[-2,2],[-2,4]$ and $[2,4]$.  The absolute differences for these pairs are $|(-2)-2|=4$, $|(-2)-4|=6$ and $|2-4|=2$.  The minimum absolute difference is $2$.

Function Description  

Complete the minimumAbsoluteDifference function in the editor below.  It should return an integer that represents the minimum absolute difference between any pair of elements.  

minimumAbsoluteDifference has the following parameter(s):  

int arr[n]: an array of integers  

Returns  

int:  the minimum absolute difference found

Input Format

The first line contains a single integer $n$, the size of $\textbf{arr}$. 

The second line contains $n$ space-separated integers, $arr\left[i\right]$.   

Constraints

$2\leq n\leq10^5$  
$-10^9\leq arr[i]\leq10^9$  

Sample Input 0
3
3 -7 0

Sample Output 0
3

Explanation 0

The first line of input is the number of array elements.  The array, $arr=[3,-7,0]$  There are three pairs to test: $(3,-7)$, $(3,0)$, and $\left({-7,0}\right)$. The absolute  differences are:

$|3--7|\Rightarrow10$  
$|3-0|\Rightarrow3$  
$|-7-0|\Rightarrow7$  

Remember that the order of values in the subtraction does not influence the result.   The smallest of these absolute differences is $3$.

Sample Input 1
10
-59 -36 -13 1 -53 -92 -2 -96 -54 75

Sample Output 1
1

Explanation 1

The smallest absolute difference is $|-54--53|=1$.

Sample Input 2
5
1 -3 71 68 17

Sample Output 2
3

Explanation 2

The minimum absolute difference is $|71-68|=3$.

Source: hackerrank | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
m = a[-1] - a[0]
for i in range(1, n):
	if a[i] - a[i - 1] < m:
		m = a[i] - a[i - 1]
print(m)


import sys
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
b = [a[i + 1] - a[i] for i in range(n - 1)]
print(min(b))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_value = a[1] - a[0]
for i in range(n - 1):
	if a[i + 1] - a[i] < min_value:
		min_value = a[i + 1] - a[i]
print(min_value)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
record = a[n - 1] - a[0]
for i in range(n - 1):
	if a[i + 1] - a[i] < record:
		record = a[i + 1] - a[i]
print(record)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_diff = a[n - 1] - a[0]
for i in range(1, n):
	min_diff = min(a[i] - a[i - 1], min_diff)
print(min_diff)


import sys
import math
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
best = float('inf')
for i in range(len(a) - 1):
	best = min(a[i + 1] - a[i], best)
print(best)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_dist = abs(a[0] - a[1])
for i in range(len(a) - 1):
	dist = abs(a[i] - a[i + 1])
	if dist < min_dist:
		min_dist = dist
print(min_dist)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
m = abs(a[0] - a[-1])
for i in range(len(a) - 1):
	c = abs(a[i] - a[i + 1])
	if c < m:
		m = c
	if not m:
		break
print(m)


import sys
absdiff = -1
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
for i in range(1, len(a)):
	diff = abs(a[i] - a[i - 1])
	if diff < absdiff or absdiff == -1:
		absdiff = diff
print(absdiff)


import collections
import math
import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
i = 0
minDif = float('inf')
while i < n - 1:
	if abs(a[i] - a[i + 1]) < minDif:
		minDif = abs(a[i] - a[i + 1])
	i += 1
print(minDif)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min = a[len(a) - 1] - a[0]
for i in range(len(a) - 1):
	dif = abs(a[i] - a[i + 1])
	if dif < min:
		min = dif
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff = 10000000
for i in range(n - 1):
	if a[i + 1] - a[i] < diff:
		diff = a[i + 1] - a[i]
print(diff)


import sys
n = int(input().strip())
l = list(map(int, input().strip().split()))
f = abs(l[0] - l[1])
l = sorted(l)
for i in range(len(l) - 1):
	if abs(l[i] - l[i + 1]) < f:
		f = abs(l[i] - l[i + 1])
print(f)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_diff = abs(a[0] - a[1])
for i in range(1, len(a) - 1):
	min_diff = min(min_diff, abs(a[i] - a[i + 1]))
print(min_diff)


input()
values = [int(x) for x in input().strip().split()]
curMin = None
values.sort()
for i in range(len(values) - 1):
	t = abs(values[i] - values[i + 1])
	if curMin is None or t < curMin:
		curMin = t
print(curMin)


import sys

def min_abs_dist(vec):
	vec.sort()
	prev = vec[0]
	min_dist = float('inf')
	for cur in vec[1:]:
		dist = abs(cur - prev)
		if dist < min_dist:
			min_dist = dist
		prev = cur
	return min_dist
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
min_dist = min_abs_dist(a)
print(min_dist)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
diff = float('inf')
a.sort()
for i in range(1, len(a)):
	if diff == 0:
		break
	if a[i] - a[i - 1] < diff:
		diff = a[i] - a[i - 1]
print(diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
minm = 10000000000
a = sorted(a)
for i in range(len(a) - 1):
	diff = abs(a[i] - a[i + 1])
	if minm > diff:
		minm = diff
print(minm)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
mini = abs(a[0] - a[1])
for i in range(1, len(a) - 1):
	if abs(a[i] - a[i + 1]) < mini:
		mini = abs(a[i] - a[i + 1])
print(mini)


import sys
from math import *
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff = 999999999999999
for x in range(len(a) - 1):
	if abs(a[x + 1] - a[x]) < diff:
		diff = abs(a[x + 1] - a[x])
print(diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
minDiff = a[1] - a[0]
for i in range(2, len(a)):
	minDiff = min(minDiff, a[i] - a[i - 1])
print(minDiff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
minimum = abs(a[0] - a[1])
for i in range(1, n - 1):
	if abs(a[i + 1] - a[i]) < minimum:
		minimum = a[i + 1] - a[i]
print(minimum)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
wynik = a[1] - a[0]
for i in range(2, n):
	wynik = min(wynik, a[i] - a[i - 1])
print(wynik)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split()))
a.sort()
minDiff = 2000000000
for i in range(n - 1):
	diff = abs(a[i + 1] - a[i])
	if diff < minDiff:
		minDiff = diff
print(minDiff)


import sys
import itertools
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
tuples = []
first = 0
second = 1
for element in range(0, len(a) - 1):
	tup = (a[first], a[second])
	tuples.append(tup)
	first += 1
	second += 1
differences = []
for t in tuples:
	difference = t[1] - t[0]
	differences.append(difference)
print(min(differences))


import sys
seen_numbers = set()
found = False
smallest = None
n = int(input().strip())
for i in map(int, input().strip().split(' ')):
	if i in seen_numbers:
		print('0')
		found = True
		break
	seen_numbers.add(i)
if not found:
	sorted_list = sorted(seen_numbers)
	for i in range(len(sorted_list) - 1):
		small = abs(sorted_list[i] - sorted_list[i + 1])
		if smallest == None:
			smallest = small
		elif small < smallest:
			smallest = small
	print(smallest)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
z = sorted(a)
pairs = [z[i:i + 2] for i in range(len(z) - 1)]
pairs
difs = [abs(a - b) for (a, b) in pairs]
print(min(difs))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
s = sorted(a)
print(min((abs(y - x) for (x, y) in zip(s, s[1:]))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
result = a[-1] - a[0]
for i in range(len(a) - 1):
	tmp = abs(a[i + 1] - a[i])
	if tmp < result:
		result = tmp
print(result)


import sys
N = int(input().strip())
a = sorted(map(int, input().strip().split(' ')))
print(min(map(lambda i: a[i + 1] - a[i], range(N - 1))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
b = [abs(i - j) for (i, j) in zip(a[1:], a[:-1])]
print(min(b))


import sys

def main():
	n = int(input().strip())
	a = list(map(int, input().strip().split(' ')))
	QuickSort(a, 0, len(a) - 1)
	(i, minimum) = (0, 0)
	while i < n - 1:
		if i == 0:
			minimum = abs(a[i] - a[i + 1])
		elif abs(a[i] - a[i + 1]) < minimum:
			minimum = abs(a[i] - a[i + 1])
		i = i + 1
	print(minimum)

def QuickSort(array, start, end):
	if start > end or start < 0:
		return array
	pivot = PartitionArray(array, start, end)
	QuickSort(array, pivot + 1, end)
	QuickSort(array, start, pivot - 1)

def PartitionArray(array, start, end):
	pivot = start
	i = start + 1
	for j in range(start + 1, end + 1):
		if array[j] < array[pivot]:
			(array[j], array[i]) = (array[i], array[j])
			i = i + 1
	(array[pivot], array[i - 1]) = (array[i - 1], array[pivot])
	return i - 1
main()


n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort(reverse=True)
m = abs(a[1] - a[0])
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) < m:
		m = abs(a[i] - a[i + 1])
print(m)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff = 10 ** 10
for s in range(n - 1):
	if abs(a[s] - a[s + 1]) < diff:
		diff = abs(a[s] - a[s + 1])
print(diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
if len(a) == 1:
	print(0)
else:
	print(min((abs(a[i] - a[i + 1]) for i in range(0, len(a) - 1))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
min = abs(a[0] - a[1])
a.sort()
for i in range(1, n - 1):
	abs_num = abs(a[i] - a[i + 1])
	if abs_num < min:
		min = abs_num
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
l = len(a)
a.sort()
value = max(a)
for i in range(l):
	if abs(a[i - 1] - a[i]) < value:
		value = abs(a[i - 1] - a[i])
print(value)


n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
mini = a[-1] - a[-2]
for i in range(len(a) - 2, 1, -1):
	temp = a[i] - a[i - 1]
	if temp < mini:
		mini = temp
print(mini)


import sys
n = int(input().strip())
a = [int(temp) for temp in input().strip().split(' ')]
a.sort()
mindiff = 1000000000
for i in range(len(a) - 1):
	if abs(a[i] - a[i + 1]) < mindiff:
		mindiff = abs(a[i] - a[i + 1])
print(mindiff)


import sys
from itertools import combinations
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
mini = abs(a[0] - a[1])
for cpt in range(1, len(a) - 1):
	if abs(a[cpt] - a[cpt + 1]) < mini:
		mini = abs(a[cpt] - a[cpt + 1])
print(mini)


import sys
import math
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min = 1000
for i in range(0, n - 1):
	if abs(a[i] - a[i + 1]) < min:
		min = abs(a[i] - a[i + 1])
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
mini = float('inf')
for i in range(1, len(a)):
	if abs(a[i] - a[i - 1]) <= mini:
		mini = abs(a[i] - a[i - 1])
print(int(mini))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_diff = 100000 ** 2
for i in range(len(a) - 1):
	if abs(a[i + 1] - a[i]) < min_diff:
		min_diff = abs(a[i + 1] - a[i])
print(min_diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
assert n == len(a)
assert n > 0
a = sorted(a)
out = a[-1] - a[0]
for (a1, a2) in zip(a[0:], a[1:]):
	da = a2 - a1
	if da < out:
		out = da
print(out)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
print(min([a[k] - a[k - 1] for k in range(1, n)]))


input()
xs = sorted((int(i) for i in input().split()))
result = min((j - i for (i, j) in zip(xs[:-1], xs[1:])))
print(result)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff_l = []
for i in range(n - 1):
	diff = abs(a[i] - a[i + 1])
	diff_l.append(diff)
print(min(diff_l))


n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
result = min((a[i + 1] - a[i] for i in range(len(a) - 1)))
print(result)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
min = sys.maxsize
a = sorted(a)
for i in range(1, n):
	tmp = abs(a[i - 1] - a[i])
	if tmp < min:
		min = tmp
	if min == 0:
		print(min)
		sys.exit()
print(min)
sys.exit()


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
m = abs(a[-1])
for x in range(0, n - 1):
	t = abs(a[x] - a[x + 1])
	if t < m:
		m = t
print(m)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
minn = 9999999999
for i in range(n - 1):
	x = abs(a[i] - a[i + 1])
	if minn > x:
		minn = x
		if minn == 0:
			break
print(minn)


import math
import sys
n = int(input().strip())
types = list(map(int, input().strip().split(' ')))
out = sys.maxsize
types.sort()
for i in range(0, n - 1):
	a = math.fabs(types[i] - types[i + 1])
	if a < out:
		out = a
print(int(out))


g = int(input())
nums = input().split(' ')
for i in range(0, len(nums)):
	nums[i] = int(nums[i])
nums.sort()
min = 1000000
for i in range(1, len(nums)):
	temp = abs(nums[i] - nums[i - 1])
	if temp < min:
		min = temp
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
z = list()
for x in range(len(a) - 1):
	z += [a[x + 1] - a[x]]
print(min(z))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min = 10000000
for i in range(0, len(a)):
	temp = abs(a[i] - a[i - 1])
	if temp < min:
		min = temp
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_abdf = abs(a[0] - a[1])
for i in range(1, n - 1):
	if abs(a[i] - a[i + 1]) < min_abdf:
		min_abdf = abs(a[i] - a[i + 1])
print(min_abdf)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff = 100000000000000000000000
for i in range(0, n - 1, 1):
	if a[i + 1] - a[i] < diff:
		diff = a[i + 1] - a[i]
print(diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
val = max(a) + 1
a.sort()
for i in range(1, n):
	if abs(a[i - 1] - a[i]) < val:
		val = abs(a[i - 1] - a[i])
print(val)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
min = sys.maxsize
a.sort(reverse=False)
for i in range(0, n - 1):
	x = abs(a[i] - a[i + 1])
	if x < min:
		min = x
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
mn = a[-1] - a[0]
for i in range(n - 1):
	if a[i + 1] - a[i] < mn:
		mn = a[i + 1] - a[i]
print(mn)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
diff = 2 * 10 ** 9
for i in range(n - 1):
	m = a[i + 1] - a[i]
	if m < diff:
		diff = m
print(diff)


import sys
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
print(min((abs(a[i + 1] - a[i]) for i in range(len(a) - 1))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
absMinimum = abs(max(min(a), max(a), key=abs))
a.sort()
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) < absMinimum:
		absMinimum = abs(a[i] - a[i + 1])
print(absMinimum)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
new_a = []
for index in range(len(a) - 1):
	new_a.append(abs(a[index] - a[index + 1]))
print(min(new_a))


fun = lambda a, b: abs(a - b)
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
m = 2 * 10 ** 9 + 1
for i in range(n - 1):
	m = min(m, abs(a[i] - a[i + 1]))
print(m)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
if len(set(a)) < len(a):
	print(0)
else:
	a.sort()
	b = [abs(a[i] - a[i + 1]) for i in range(len(a) - 1)]
	b.sort()
	print(b[0])


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
minn = a[0] - a[1]
if minn < 0:
	minn = -minn
h = 0
while h <= len(a) - 2:
	neww = a[h] - a[h + 1]
	if neww < 0:
		neww = -neww
	if neww < minn:
		minn = neww
	h = h + 1
print(minn)


import sys

def minabs(a):
	a.sort()
	min_abs = abs(a[0] - a[1])
	for i in range(0, len(a) - 1, 1):
		new_abs = abs(a[i] - a[i + 1])
		if min_abs > new_abs:
			min_abs = new_abs
		if min_abs == 0:
			break
	print(min_abs)
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
minabs(a)


import sys
import math
n = int(input().strip())
A = list(map(int, input().strip().split(' ')))
A.sort()
m = 1000000
for i in range(1, n):
	m = min(int(math.fabs(A[i] - A[i - 1])), m)
print(m)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
min = abs(a[0] - a[1])
for i in range(1, n - 1):
	diff = abs(a[i] - a[i + 1])
	if diff < min:
		min = diff
print(min)


import sys
min_d = 10000000
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
for i in range(len(a) - 1):
	d = abs(a[i] - a[i + 1])
	if d < min_d:
		min_d = d
print(min_d)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
min = max(map(lambda x: abs(x), a))
for i in range(1, len(a)):
	diff = a[i] - a[i - 1]
	if diff < min:
		min = diff
print(min)


import sys
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
print(min((y - x for (x, y) in zip(a, a[1:]))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min = 9999
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) < min:
		min = abs(a[i] - a[i + 1])
	if min < 1:
		break
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_diff = a[1] - a[0]
for i in range(len(a) - 1):
	diff = a[i + 1] - a[i]
	if diff < min_diff:
		min_diff = diff
print(min_diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
min_dif = abs(a[0] - a[1])
for i in range(0, len(a) - 1):
	min_dif = min(abs(a[i] - a[i + 1]), min_dif)
print(min_dif)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
mi = 10000000000000
for i in range(n - 1):
	diff = a[i + 1] - a[i]
	if diff < mi:
		mi = diff
print(mi)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
minT = 100000
for i in range(n - 1):
	min1 = abs(a[i] - a[i + 1])
	if min1 <= minT:
		minT = min1
print(minT)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
b = [a[i] - a[i - 1] for i in range(1, len(a))]
print(min(b))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
m = 9999999999
a.sort()
for i in range(len(a) - 1):
	m = min(a[i + 1] - a[i], m)
print(m)


import sys
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
minimum = float('inf')
for i in range(len(a) - 1):
	minimum = min(minimum, abs(a[i] - a[i + 1]))
print(minimum)


array_len = int(input())
my_list = [int(x) for x in input().split()]

def get_diff(arr):
	arr.sort()
	diff_arr = []
	for i in range(len(arr) - 1):
		diff_arr.append(abs(arr[i] - arr[i + 1]))
	print(min(diff_arr))
get_diff(my_list)


import sys
import itertools
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
n = len(a)
diff = abs(a[0] - a[0 + 1])
for i in range(n - 1):
	if diff > abs(a[i + 1] - a[i]):
		diff = abs(a[i + 1] - a[i])
print(diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
print(min((a[i] - a[i - 1] for i in range(1, len(a)))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
min_diff = 2 * 10 ** 9
end_index = n - 1
for (index, num) in enumerate(a):
	if index < end_index:
		min_diff = min(min_diff, abs(num - a[index + 1]))
		if min_diff == 0:
			break
print(min_diff)


import math, sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
arr = sorted(a)
med = sys.maxsize
for i in range(len(arr) - 1):
	j = i + 1
	med = min(med, abs(arr[i] - arr[j]))
print(abs(med))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
print(min((abs(x - y) for (x, y) in zip(a, a[1:]))))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a, reverse=True)
if n >= 2:
	mino = a[0] - a[1]
else:
	print(a)
for i in range(len(a) - 1):
	mino = min(mino, a[i] - a[i + 1])
print(mino)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
difference = abs(a[1] - a[0])
for i in range(0, len(a)):
	if i + 1 < len(a):
		if abs(a[i + 1] - a[i]) < difference:
			difference = abs(a[i + 1] - a[i])
print(difference)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
b = sorted(a)
v = [abs(b[i + 1] - b[i]) for i in range(n - 1)]
print(min(v))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
b = set(a)
a_len = len(a)
b_len = len(b)
min_abs_diff = 0
if b_len < a_len:
	print(min_abs_diff)
else:
	b = sorted(list(b))
	min_abs_diff = b[1] - b[0]
	for step in range(2, n):
		diff = b[step] - b[step - 1]
		if diff < min_abs_diff:
			min_abs_diff = diff
	print(min_abs_diff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
s = sorted(a)
diff = s[1] - s[0]
for i in range(len(s) - 1):
	new_diff = s[i + 1] - s[i]
	if new_diff == 0:
		print(0)
		sys.exit()
	elif new_diff < diff:
		diff = new_diff
print(diff)


import sys
n = int(input().strip())
a = sorted(list(map(int, input().strip().split(' '))))
minDiff = abs(a[0] - a[1])
for i in range(n - 1):
	diff = abs(a[i] - a[i + 1])
	if diff < minDiff:
		minDiff = diff
print(minDiff)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
b = sorted(a)
c = [b[i + 1] - b[i] for i in range(n - 1)]
print(min(c))


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
minm = sys.maxsize
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) < minm:
		minm = abs(a[i] - a[i + 1])
print(minm)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a = sorted(a)
min = abs(a[0] - a[1])
for i in range(len(a) - 1):
	if abs(a[i] - a[i + 1]) < min:
		min = abs(a[i] - a[i + 1])
print(min)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
minrange = None
aa = sorted(a)
for i in range(len(aa) - 1):
	if minrange == 0:
		break
	crange = abs(aa[i] - aa[i + 1])
	if minrange is None or minrange > crange:
		minrange = crange
print(minrange)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
minimum = 10 ** 10
for i in range(n - 1):
	absdiff = a[i + 1] - a[i]
	if absdiff < minimum:
		minimum = absdiff
print(minimum)


import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
a.sort()
print(min([abs(a[index] - a[index + 1]) for index in range(0, len(a) - 1)]))