Ishaan being curious as always was playing with numbers when he started to reverse the numbers. He invented something called the "inverting factor" of two numbers.
The inverting Factor of 2 integers is defined as the absolute difference between the reverse of the 2 integers.
Ishaan has an array A of N integers. He wants to find out the smallest possible Inverting Factor among all pairs of his integers. Help him find that.
Note : Trailing zeros in a number of ignored while reversing, i.e. 1200 becomes 21 when reversed.
 
Example 1:
Ã¢â¬â¹Input : arr[ ] = {56, 20, 47, 93, 45}
Output : 9
Explanation:
The minimum inverting factor is 9, of the pair (56,47)
Reverse 56 -> 65 and 47 -> 74
difference between them is 9.
Ã¢â¬â¹Example 2:
Input : arr[ ] = {48, 23, 100, 71, 56, 89} 
Output :  14 
 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function findMinimumInvertingFactor() that takes an array (arr), sizeOfArray (n), and return the smallest possible Inverting Factor among all pairs of his integers. The driver code takes care of the printing.
Expected Time Complexity: O(N*LOG(N)).
Expected Auxiliary Space: O(1).
 
Constraints : 
2 ≤ N ≤ 10^{5}
1 ≤ A[i] ≤ 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: #User function Template for python3





def findMinimumInvertingFactor (arr, n) : 

    #Complete the function



Solutions:
def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		rem = 0
		num = 0
		while arr[i] > 0:
			rem = arr[i] % 10
			num = num * 10 + rem
			arr[i] = arr[i] // 10
		arr[i] = num
	arr.sort()
	max = 98783
	for i in range(n - 1, 0, -1):
		diff = abs(arr[i] - arr[i - 1])
		if diff < max:
			max = diff
	return max


import sys

def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	d = sys.maxsize
	for k in range(n - 1):
		a = abs(arr[k] - arr[k + 1])
		if a < d:
			d = a
	return d


def findMinimumInvertingFactor(arr, n):
	ls = []
	for i in arr:
		j = str(i)
		ls.append(int(j[::-1]))
	min_diff = 10000
	for i in range(0, n):
		for j in range(i + 1, n):
			diff = abs(ls[i] - ls[j])
			if diff < min_diff:
				min_diff = diff
	return min_diff


def findMinimumInvertingFactor(arr, n):
	min_diff = float('inf')
	for index in range(n):
		arr[index] = int(str(arr[index])[::-1])
	for index in range(n):
		for inner in range(index + 1, n):
			diff = abs(arr[index] - arr[inner])
			min_diff = diff if diff < min_diff else min_diff
	return min_diff


def findMinimumInvertingFactor(arr, n):
	brr = []
	for item in arr:
		brr.append(int(str(item)[::-1]))
	brr.sort()
	mini = float('inf')
	for i in range(n - 1):
		mini = min(mini, brr[i + 1] - brr[i])
	return mini


def findMinimumInvertingFactor(arr, n):
	lst = []
	l = []
	for i in arr:
		i = str(i)
		k = i[::-1]
		k = int(k)
		lst.append(k)
	lst.sort()
	for i in range(n - 1):
		t = lst[i + 1] - lst[i]
		l.append(t)
	return min(l)


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		rem = 0
		num = 0
		while arr[i] > 0:
			rem = arr[i] % 10
			num = num * 10 + rem
			arr[i] = arr[i] // 10
		arr[i] = num
	arr.sort()
	lst = []
	for i in range(n - 1):
		k = arr[i + 1] - arr[i]
		lst.append(k)
	return min(lst)


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	mi = max(arr)
	for i in range(1, n):
		mi = min(arr[i] - arr[i - 1], mi)
	return mi


def findMinimumInvertingFactor(arr, n):
	l = []
	for s in arr:
		r = int(str(s)[::-1])
		l.append(r)
	l.sort()
	min = 999999
	for c in range(n - 1):
		a = abs(l[c] - l[c + 1])
		if min > a:
			min = a
	return min


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	diff = 10 ** 7
	for i in range(n - 1):
		if arr[i + 1] - arr[i] < diff:
			diff = arr[i + 1] - arr[i]
	return diff


def findMinimumInvertingFactor(arr, n):
	k = []
	m = []
	for i in arr:
		j = str(i)
		k += [int(j[::-1])]
	for i in range(0, len(k) - 1):
		for j in range(i + 1, len(k)):
			m += [abs(k[i] - k[j])]
	return min(m)


def findMinimumInvertingFactor(arr, n):
	s = sorted(arr)
	d = []
	for i in s:
		d.append(int(str(i)[::-1]))
	x = []
	f = 0
	d = sorted(d)
	for i in range(1, n):
		if d.count(d[i]) > 1:
			return 0
		f = abs(d[i] - d[i - 1])
		x.append(f)
	return min(x)


def findMinimumInvertingFactor(arr, n):
	p = []
	for i in range(n):
		arr[i] = str(arr[i])
		c = int(arr[i][::-1])
		p.append(c)
	p.sort()
	k = []
	for i in range(len(p) - 1):
		k.append(p[i + 1] - p[i])
	return min(k)


def findMinimumInvertingFactor(arr, n):
	res = 10000000007
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	res = 100000007
	for i in range(n - 1):
		d = abs(arr[i] - arr[i + 1])
		res = min(res, d)
	return res


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		s = 0
		a = arr[i]
		while a > 0:
			s = s * 10 + a % 10
			a = a // 10
		arr[i] = s
	arr.sort()
	mn = 1000000
	for i in range(n - 1):
		s = arr[i + 1] - arr[i]
		if mn > s:
			mn = s
	return mn


def findMinimumInvertingFactor(arr, n):
	lis = []
	for i in range(n):
		k = str(arr[i])
		k = k[::-1]
		lis.append(int(k))
	lis.sort()
	d = 10000000
	for i in range(0, len(lis) - 1):
		ans = lis[i + 1] - lis[i]
		if ans < d:
			d = ans
	return d


def findMinimumInvertingFactor(a, n):
	min = 10000000
	for i in range(n - 1):
		k = int(str(arr[i])[::-1])
		for j in range(i + 1, n):
			if min > abs(k - int(str(arr[j])[::-1])):
				min = abs(k - int(str(arr[j])[::-1]))
	return min


def findMinimumInvertingFactor(arr, n):
	g = []
	l = []
	m = 0
	for i in arr:
		l.append(int(str(i)[::-1]))
	l = sorted(l)
	for i in range(1, len(l)):
		g.append(l[i] - l[i - 1])
	return min(g)


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	a = sorted(arr)
	b = []
	for i in range(1, n):
		b.append(a[i] - a[i - 1])
	return min(b)


def findMinimumInvertingFactor(arr, n):
	res = []
	for i in arr:
		temp = str(i)
		temp = temp[::-1]
		res.append(int(temp))
	res.sort()
	ans = res[-1]
	for i in range(n - 1):
		temp = abs(res[i] - res[i + 1])
		if temp < ans:
			ans = temp
	return ans


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(''.join(reversed(str(arr[i]))))
	arr.sort()
	s = 999999
	for k in range(0, n - 1):
		a = abs(arr[k] - arr[k + 1])
		if a < s:
			s = a
	return s


def findMinimumInvertingFactor(arr, n):
	l = []
	l1 = []
	for i in arr:
		a = str(i)
		a = a[::-1]
		l.append(int(a))
	l.sort()
	for x in range(0, len(l) - 1):
		l1.append(abs(l[x] - l[x + 1]))
	return min(l1)


def findMinimumInvertingFactor(arr, n):

	def reverse(obj):
		new = str(obj)
		a = len(new)
		m = obj % 10
		if m == obj:
			return m
		else:
			return reverse(obj // 10) + 10 ** (a - 1) * m
	sum = []
	for i in arr:
		b = reverse(i)
		sum = sum + [b]
	new = 0
	n = len(sum)
	for i in range(n):
		value = sum[i]
		sum.pop(i)
		for j in range(n - 1):
			a = abs(value - sum[j])
			if a == 0:
				return 0
			elif new == 0:
				new = a
			elif a < new:
				new = a
			else:
				new = new
		sum.insert(i, value)
	return new


def revN(n):
	rv = 0
	while n > 0:
		rv = rv * 10 + n % 10
		n //= 10
	return rv

def findMinimumInvertingFactor(arr, n):
	arr = sorted(arr)
	rev = sorted([revN(i) for i in arr])
	sm = None
	for i in range(n - 1):
		if sm is None or sm > abs(rev[i] - rev[i + 1]):
			sm = abs(rev[i] - rev[i + 1])
	return sm


def reverse_num(n):
	rev = 0
	temp2 = n
	while temp2 != 0:
		r = temp2 % 10
		rev = rev * 10 + r
		temp2 = temp2 // 10
	return rev

def findMinimumInvertingFactor(arr, n):
	rev_arr = []
	mini = float('inf')
	for i in range(0, len(arr)):
		rev_arr.append(reverse_num(arr[i]))
	rev_arr.sort()
	for i in range(0, len(arr) - 1):
		d = abs(rev_arr[i + 1] - rev_arr[i])
		if d < mini:
			mini = d
	return mini


import sys

def findMinimumInvertingFactor(arr, n):
	N = n
	ans = sys.maxsize
	for i in range(N):
		num = arr[i]
		s = ''
		while num > 0:
			s += str(num % 10)
			num //= 10
		for pos in range(len(s)):
			if s[pos] != '0':
				break
		num = 0
		for j in range(pos, len(s)):
			num = num * 10 + (ord(s[j]) - ord('0'))
		arr[i] = num
	arr.sort()
	for i in range(N):
		ans = min(ans, abs(arr[i] - arr[i - 1]))
	return ans


def findMinimumInvertingFactor(arr, n):
	result = []
	for i in range(n):
		result.append(int(str(arr[i])[::-1]))
	result.sort()
	new_result = []
	for i in range(n - 1):
		new_result.append(abs(result[i] - result[i + 1]))
	return min(new_result)


def reverse(num):
	n = 0
	while num > 0:
		n = n * 10 + num % 10
		num //= 10
	return n

def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = reverse(arr[i])
	arr.sort()
	mn = 1000000000
	for i in range(1, n):
		mn = min(mn, arr[i] - arr[i - 1])
	return mn


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		omkey = str(arr[i])
		arr[i] = int(omkey[::-1])
	arr.sort()
	hue = 1000000
	for j in range(n - 1):
		hue = min(hue, arr[j + 1] - arr[j])
	return hue


def findMinimumInvertingFactor(arr, n):
	rev_arr = []
	small_diff = 999999
	for i in arr:
		rev_arr.append(int(str(i)[::-1]))
	rev_arr.sort()
	for j in range(n - 1):
		if small_diff > abs(rev_arr[j + 1] - rev_arr[j]):
			small_diff = abs(rev_arr[j + 1] - rev_arr[j])
	return small_diff


def rev(n):
	x = n
	sum = 0
	while True:
		a = x % 10
		x = x // 10
		sum = sum + a
		if x > 0:
			sum = sum * 10
		else:
			break
	return sum

def findMinimumInvertingFactor(arr, n):
	for i in range(len(arr)):
		arr[i] = rev(arr[i])
	arr.sort()
	mini = arr[1] - arr[0]
	for i in range(1, len(arr)):
		mini = min(mini, arr[i] - arr[i - 1])
	return mini


def findMinimumInvertingFactor(arr, n):
	x = [int(str(i)[::-1]) for i in arr]
	x.sort()
	d = 99999
	for k in range(n - 1):
		a = abs(x[k] - x[k + 1])
		if a < d:
			d = a
	return d


def findMinimumInvertingFactor(arr, n):
	a = []
	for i in arr:
		temp = i
		s = 0
		while temp:
			s = s * 10 + temp % 10
			temp //= 10
		a.append(s)
	a = sorted(a)
	m = 10000
	for i in range(1, len(a)):
		k = abs(a[i - 1] - a[i])
		if m > k:
			m = k
	return m


def findMinimumInvertingFactor(arr, n):
	arr2 = []
	fac = 99999
	for i in arr:
		arr2.append(int(str(i)[::-1]))
	arr2.sort()
	for i in range(0, n - 1):
		if arr2[i + 1] - arr2[i] < fac:
			fac = arr2[i + 1] - arr2[i]
	return fac


def findMinimumInvertingFactor(arr, n):
	s = []
	for i in arr:
		i = str(i)
		i = i[::-1]
		s.append(i)
	m = []
	for i in range(0, n):
		for j in range(i + 1, n):
			m.append(abs(int(s[i]) - int(s[j])))
	return min(m)


def getReverseNum(arr, n):
	rev = []
	for i in range(n):
		num = str(arr[i])
		rev.append(int(num[::-1]))
	return rev

def findMinimumInvertingFactor(arr, n):
	lst = getReverseNum(arr, n)
	lst.sort()
	min_diff = 12345678
	for i in range(1, n):
		diff = abs(lst[i] - lst[i - 1])
		min_diff = min(min_diff, diff)
	return min_diff


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		d = str(arr[i])
		arr[i] = int(d[::-1])
	arr.sort()
	d = 999999999
	for i in range(n - 1):
		e = arr[i + 1] - arr[i]
		if e < d:
			d = e
	return d


def findMinimumInvertingFactor(arr, n):
	a = []
	for item in arr:
		num = item
		reverse_num = 0
		while num != 0:
			digit = num % 10
			reverse_num = reverse_num * 10 + digit
			num = num // 10
		a.append(reverse_num)
	s = 0
	b = []
	for i in range(len(a)):
		for j in range(i + 1, len(a)):
			b.append(abs(a[i] - a[j]))
	return min(b)


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	res = arr[1] - arr[0]
	for i in range(2, n):
		res = min(res, arr[i] - arr[i - 1])
	return res


def findMinimumInvertingFactor(arr, n):
	arr = [str(ele) for ele in arr]
	rev_arr = [int(ele[::-1]) for ele in arr]
	rev_arr.sort()
	min_diff = rev_arr[1] - rev_arr[0]
	for i in range(1, n):
		min_diff = min(min_diff, rev_arr[i] - rev_arr[i - 1])
	return min_diff
for _ in range(0, int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ans = findMinimumInvertingFactor(arr, n)
	print(ans)


def findMinimumInvertingFactor(arr, n):
	rev = []
	for i in range(n):
		s = str(arr[i])[::-1]
		rev.append(int(s))
	rev.sort()
	min = rev[1] - rev[0]
	for i in range(2, n):
		if rev[i] - rev[i - 1] < min:
			min = rev[i] - rev[i - 1]
	return min
for _ in range(0, int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ans = findMinimumInvertingFactor(arr, n)
	print(ans)


def findMinimumInvertingFactor(arr, n):
	rev_arr = []
	small_diff = 999999
	for i in arr:
		rev_arr.append(int(str(i)[::-1]))
	rev_arr.sort()
	for j in range(n - 1):
		if small_diff > abs(rev_arr[j + 1] - rev_arr[j]):
			small_diff = abs(rev_arr[j + 1] - rev_arr[j])
	return small_diff
for _ in range(0, int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ans = findMinimumInvertingFactor(arr, n)
	print(ans)


def findMinimumInvertingFactor(a, n):
	for i in range(len(a)):
		digit = 0
		tmp = a[i]
		while tmp:
			digit += 1
			tmp //= 10
		revdigit = 0
		digit -= 1
		while digit >= 0:
			revdigit = revdigit + a[i] % 10 * pow(10, digit)
			a[i] //= 10
			digit -= 1
		a[i] = revdigit
	a.sort()
	res = a[1] - a[0]
	for i in range(2, len(a)):
		if a[i] - a[i - 1] < res:
			res = a[i] - a[i - 1]
	return res


def findMinimumInvertingFactor(arr, n):
	arr = sorted([int(str(i)[::-1]) for i in arr], reverse=True)
	res = arr[0] - arr[1]
	for i in range(1, len(arr) - 1):
		if arr[i] - arr[i + 1] < res:
			res = arr[i] - arr[i + 1]
	return res


def findMinimumInvertingFactor(arr, n):
	lst = [str(i)[::-1] for i in arr]
	lst1 = [int(i) for i in lst]
	lst1.sort()
	c = 99999999999999999999999999999
	for i in range(1, n):
		c = min(lst1[i] - lst1[i - 1], c)
	return c


def findMinimumInvertingFactor(arr, n):
	a = []
	for i in arr:
		i = str(i)
		i = i[::-1]
		a.append(int(i))
	m = 98765432
	a.sort()
	for i in range(n - 1):
		b = a[i + 1] - a[i]
		if b < m:
			m = b
	return m


def findMinimumInvertingFactor(arr, n):
	c = []
	for i in arr:
		i = str(i)
		i = i[::-1]
		i = int(i)
		c.append(i)
	c.sort()
	m = max(c)
	d = []
	d.append(m + 1)
	for i in range(0, len(c) - 1):
		x = c[i + 1] - c[i]
		d.append(x)
	return min(d)


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		temp = str(arr[i])
		temp = temp[::-1]
		arr[i] = int(temp)
	arr.sort()
	mine = 100000009
	for i in range(n - 1):
		mine = min(mine, abs(arr[i] - arr[i + 1]))
	return mine


def findMinimumInvertingFactor(arr, n):
	if n == 0:
		return 0
	if n == 1:
		return arr[0]

	def r(n):
		a = str(n)
		b = a[::-1]
		c = int(b)
		return c
	x = []
	for i in arr:
		x.append(r(i))
	x = sorted(x)
	ans = x[1] - x[0]
	for i in range(1, len(x)):
		if x[i] - x[i - 1] < ans:
			ans = x[i] - x[i - 1]
	return ans


def rev(n):
	s = 0
	while n > 0:
		s = s * 10 + n % 10
		n = n // 10
	return s

def findMinimumInvertingFactor(arr, n):
	l = []
	mi = 10 ** 9
	for i in arr:
		l.append(int(str(i)[::-1]))
	l.sort()
	for i in range(n - 1):
		if mi > abs(l[i + 1] - l[i]):
			mi = abs(l[i + 1] - l[i])
	return mi


def findMinimumInvertingFactor(arr, n):
	for i in range(len(arr)):
		d = str(arr[i])
		arr[i] = int(d[::-1])
	arr.sort()
	difference = 99999
	for i in range(1, len(arr)):
		d = arr[i] - arr[i - 1]
		if d < difference:
			difference = d
	return difference


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		temp = arr[i]
		num = 0
		while temp:
			num = num * 10 + temp % 10
			temp = temp // 10
		arr[i] = num
	arr.sort()
	k = float('inf')
	for i in range(1, n):
		k = min(k, arr[i] - arr[i - 1])
	return k


def findMinimumInvertingFactor(arr, n):
	a = []
	for i in arr:
		a.append(int(str(i)[::-1]))
	a.sort()
	b = 999999
	for i in range(n - 1):
		if b > abs(a[i + 1] - a[i]):
			b = abs(a[i + 1] - a[i])
	return b


def findMinimumInvertingFactor(arr, n):
	l = []
	for i in arr:
		k = str(i)
		k = k[::-1]
		k = int(k)
		l.append(k)
	c = 0
	m = -1
	arr[:] = l[:]
	arr.sort(reverse=True)
	for i in range(n):
		for j in range(i + 1, n):
			c = arr[i] - arr[j]
			if m == -1:
				m = c
			if c < m:
				m = c
	return m


def findMinimumInvertingFactor(arr, n):
	modArr = []
	for num in arr:
		temp = 0
		while num > 0:
			lastdigit = num % 10
			temp = temp * 10 + lastdigit
			num = num // 10
		modArr.append(temp)
	minDiff = 10 ** 7
	modArr.sort()
	for i in range(n - 1):
		if modArr[i + 1] - modArr[i] < minDiff:
			minDiff = modArr[i + 1] - modArr[i]
	return minDiff


def findMinimumInvertingFactor(arr, n):
	x = [int(str(i)[::-1]) for i in arr]
	x = sorted(x)
	m = 999999
	for i in range(n - 1):
		if m > abs(x[i + 1] - x[i]):
			m = abs(x[i + 1] - x[i])
	return m


def findMinimumInvertingFactor(a, n):
	b = []
	for i in range(n):
		r = 0
		while a[i] != 0:
			c = a[i] % 10
			r = r * 10 + c
			a[i] = a[i] // 10
		b.append(r)
	min = 999999
	b.sort()
	for i in range(n - 1):
		if min > abs(b[i + 1] - b[i]):
			min = abs(b[i + 1] - b[i])
	return min


def findMinimumInvertingFactor(arr, n):
	m = []
	d = []
	for j in arr:
		k = str(j)[::-1]
		m.append(int(k))
	for u in range(n - 1):
		for o in range(u + 1, n):
			d.append(abs(m[u] - m[o]))
	return min(d)


def findMinimumInvertingFactor(arr, n):
	m = 9999
	for i in range(0, n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	for i in range(0, n - 1):
		if abs(arr[i] - arr[i + 1]) < m:
			m = abs(arr[i] - arr[i + 1])
	return m


def findMinimumInvertingFactor(arr, n):
	mini = 999999
	l = []
	for i in range(n):
		s = str(arr[i])
		s = s[::-1]
		l.append(int(s))
	for i in range(n):
		for j in range(i + 1, n):
			if abs(l[j] - l[i]) < mini:
				mini = abs(l[j] - l[i])
	return mini


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		rev = 0
		digit = 0
		k = arr[i]
		while k != 0:
			digit = k % 10
			rev = rev * 10 + digit
			k //= 10
		arr[i] = rev
	arr.sort()
	s = arr[1] - arr[0]
	for i in range(n - 1):
		if arr[i + 1] - arr[i] <= s:
			s = arr[i + 1] - arr[i]
	return s


def findMinimumInvertingFactor(arr, n):
	b = [int(str(i)[::-1]) for i in arr]
	b.sort()
	minimum = b[1] - b[0]
	for j in range(2, n):
		if b[j] - b[j - 1] < minimum:
			minimum = b[j] - b[j - 1]
	return minimum


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		arr[i] = int(str(arr[i])[::-1])
	arr.sort()
	mn = 999999999
	for i in range(1, n):
		mn = min(mn, arr[i] - arr[i - 1])
	return mn


def findMinimumInvertingFactor(arr, n):
	Rev = [str(N)[::-1] for N in arr]
	R = [int(N) for N in Rev]
	min_diff = 100000000000000000
	for x in range(0, len(R) - 1):
		for y in range(x + 1, len(R)):
			diff = abs(R[x] - R[y])
			if diff < min_diff:
				min_diff = diff
	return min_diff


import math

def findMinimumInvertingFactor(arr, n):
	for i in range(0, n):
		arr[i] = str(arr[i])
		arr[i] = arr[i][::-1]
		arr[i] = int(arr[i])
	arr.sort()
	ans = abs(arr[1] - arr[0])
	for i in range(len(arr) - 1):
		if abs(arr[i + 1] - arr[i]) < ans:
			ans = abs(arr[i + 1] - arr[i])
	return ans


def findMinimumInvertingFactor(arr, n):
	rev = []
	for i in arr:
		if i == 0:
			continue
		else:
			rev.append(int(str(i)[::-1].strip('0')))
	rev.sort()
	mini = abs(rev[0] - rev[1])
	for i in range(0, len(rev) - 1):
		if abs(rev[i] - rev[i + 1]) < mini:
			mini = abs(rev[i] - rev[i + 1])
	return mini


def rev(x):
	y = str(x)
	z = y[::-1]
	return int(z)

def findMinimumInvertingFactor(arr, n):
	min = 10 ** 10
	for i in range(0, n):
		arr[i] = rev(arr[i])
	for i in range(0, n):
		for j in range(0, n):
			if i != j and abs(arr[i] - arr[j]) < min:
				min = abs(arr[i] - arr[j])
	return min


def findMinimumInvertingFactor(arr, n):
	for i in range(n):
		b = str(arr[i])
		a = b[::-1]
		arr[i] = int(a)
	c = []
	for j in range(n):
		for k in range(j + 1, n):
			c.append(abs(arr[j] - arr[k]))
	return min(c)


def findMinimumInvertingFactor(arr, n):
	rev = []
	for i in arr:
		no = 0
		while i > 0:
			rem = i % 10
			no = no * 10 + rem
			i = i // 10
		rev.append(no)
	rev.sort()
	min_d = float('inf')
	for i in range(n - 1):
		min_d = min(min_d, abs(rev[i] - rev[i + 1]))
	return min_d


def findMinimumInvertingFactor(arr, n):
	inv = []
	mn = []
	for item in arr:
		r = list(str(item))
		r.reverse()
		inv.append(int(''.join(r)))
	for i in range(n):
		for j in range(i + 1, n):
			mn.append(abs(inv[i] - inv[j]))
	return min(mn)


def findMinimumInvertingFactor(arr, n):
	lst = []
	for num in arr:
		lst.append(int(str(num)[::-1]))
	lst.sort()
	minmm = max(lst)
	for i in range(n - 1):
		minmm = lst[i + 1] - lst[i] if lst[i + 1] - lst[i] < minmm else minmm
	return minmm


def findMinimumInvertingFactor(arr, n):
	m = 23743647678
	l = []
	for i in range(n):
		f = list(str(arr[i]))
		f = f[::-1]
		f = int(''.join(f))
		l.append(f)
	l.sort()
	for i in range(len(l) - 1):
		if m > abs(l[i] - l[i + 1]):
			m = abs(l[i] - l[i + 1])
	return m