Given an unsorted array, find the minimum difference between any pair in given array.
 
Example 1:
Input: nums = [2, 4, 5, 9, 7]
Output: 1
Explanation: Difference between 5 and 4 is 1.
Example 2:
Input: nums = [3, 10, 8, 6]
Output: 2
Explanation: Difference between 8 and 6 is 2.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function minimum_difference() which takes the array as input parameter and returns the minimum difference  between any pair in given array.
Expected Time Compelxity: O(N* log(N)) where N is length of array.
Expected Space Complexity: O(1)
 
Constraints:
2 <= N <= 10^{5}
1 <= nums[i] <= 10^{9}

Difficulty: EASY
Tags: Sorting
Skill types: Sorting
Expected Time Complexity: O(N* log(N)) where N is length of array
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
	def minimum_difference(self, nums):
		# Code here

Solutions:
class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		ans = float('inf')
		for i in range(len(nums) - 1):
			ans = min(ans, abs(nums[i] - nums[i + 1]))
		return ans


class Solution:

	def minimum_difference(self, nums):
		res = []
		nums = sorted(nums)
		for i in range(len(nums) - 1):
			res.append(nums[i + 1] - nums[i])
		return min(res)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		an = 100000000000000
		for i in range(len(nums) - 1):
			if nums[i + 1] - nums[i] < an:
				an = nums[i + 1] - nums[i]
		return an


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		x = 0
		l = []
		for i in range(1, len(nums)):
			x = nums[i] - nums[i - 1]
			l.append(x)
		return min(l)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		m = int(1000000000.0) + 7
		for i in range(1, n):
			d = nums[i] - nums[i - 1]
			m = min(m, d)
		return m


class Solution:

	def minimum_difference(self, nums):
		a = []
		i = 0
		j = 1
		nums.sort()
		while i < len(nums) and j < len(nums):
			s = abs(nums[i] - nums[j])
			a.append(s)
			i += 1
			j += 1
		return min(a)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		a = max(nums)
		for i in range(len(nums) - 1):
			if nums[i + 1] - nums[i] < a:
				a = nums[i + 1] - nums[i]
		return a


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		diff = 99999
		for i in range(1, len(nums)):
			if nums[i] - nums[i - 1] < diff:
				diff = nums[i] - nums[i - 1]
		return diff


class Solution:

	def minimum_difference(self, nums):
		n = len(nums)
		nums.sort()
		diff = 10 ** 20
		for i in range(n - 1):
			if nums[i + 1] - nums[i] < diff:
				diff = nums[i + 1] - nums[i]
		return diff


class Solution:

	def minimum_difference(self, nums):
		n = len(nums)
		nums.sort()
		a = []
		for i in range(n - 1):
			d = abs(nums[i] - nums[i + 1])
			a.append(d)
		res = min(a)
		return res


class Solution:

	def minimum_difference(self, nums):
		if not nums:
			return
		nums.sort()
		minimal = float('inf')
		i = 0
		j = i + 1
		while j < len(nums):
			diff = nums[j] - nums[i]
			if diff < minimal:
				minimal = diff
			i += 1
			j += 1
		return minimal


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		minimum = max(nums)
		for i in range(len(nums) - 1):
			difference = nums[i + 1] - nums[i]
			minimum = min(minimum, difference)
		return minimum


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		ans = 99999
		for i in range(len(nums) - 1):
			if abs(nums[i] - nums[i + 1]) < ans:
				ans = abs(nums[i] - nums[i + 1])
		return ans


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		arr = []
		for i in range(len(nums) - 1):
			d = nums[i + 1] - nums[i]
			arr.append(d)
		return min(arr)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		res = abs(nums[0] - nums[1])
		for i in range(1, len(nums) - 1):
			res = min(res, abs(nums[i] - nums[i + 1]))
		return res


class Solution:

	def minimum_difference(self, nums):
		a = []
		n = sorted(nums)
		for i in range(len(n) - 1):
			a.append(n[i + 1] - n[i])
		return min(a)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		ans = 999999999
		for i in range(1, len(nums)):
			c = abs(nums[i - 1] - nums[i])
			ans = min(ans, c)
		return ans


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		min_ = 999999
		for i in range(len(nums) - 1):
			diff = nums[i + 1] - nums[i]
			if min_ > diff:
				min_ = diff
		return min_


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		a = 99999999
		for i in range(len(nums) - 1):
			a = min(a, abs(nums[i] - nums[i + 1]))
		return a


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mins = []
		for i in range(len(nums) - 1):
			mins.append(abs(nums[i] - nums[i + 1]))
		return min(mins)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		ans = 10000000000
		for i in range(n - 1):
			ans = min(ans, abs(nums[i] - nums[i + 1]))
		return ans


class Solution:

	def minimum_difference(self, arr):
		arr.sort()
		n = len(arr)
		if n == 1:
			return a[0]
		ans = arr[1] - arr[0]
		for i in range(1, n):
			ans = min(arr[i] - arr[i - 1], ans)
		return ans


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		smlest_sub = 2147483647
		check_num = 0
		for i in range(0, len(nums) - 1):
			check_num = abs(nums[i] - nums[i + 1])
			if smlest_sub > check_num:
				smlest_sub = check_num
		return smlest_sub


class Solution:

	def minimum_difference(self, nums):
		num1 = sorted(nums)
		dif = 10 ** 20
		for i in range(0, len(num1) - 1):
			dif = min(dif, abs(num1[i + 1] - num1[i]))
		return dif


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mini = c = nums[1] - nums[0]
		for i in range(len(nums) - 1):
			c = nums[i + 1] - nums[i]
			mini = min(mini, c)
		return mini


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		min_diff = 1000000000000000000
		for idx in range(len(nums) - 1):
			diff = abs(nums[idx] - nums[idx + 1])
			min_diff = diff if diff < min_diff else min_diff
		return min_diff


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		minn = 10 ** 5
		for i in range(len(nums) - 1):
			diff = nums[i + 1] - nums[i]
			minn = min(diff, minn)
		return minn


class Solution:

	def minimum_difference(self, nums):
		mindiff = 999999
		nums.sort()
		for i in range(len(nums) - 1):
			diff = abs(nums[i] - nums[i + 1])
			mindiff = min(diff, mindiff)
		return mindiff


class Solution:

	def minimum_difference(self, arr):
		k = []
		arr.sort()
		for i in range(n - 1):
			d = abs(arr[i] - arr[i + 1])
			k.append(d)
		return min(k)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		res = float('inf')
		for i in range(1, n):
			res = min(res, nums[i] - nums[i - 1])
		return res


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mn = min((nums[i] - nums[i - 1] for i in range(1, len(nums))))
		return mn


class Solution:

	def minimum_difference(self, nums):
		(prev, diff) = (-1, 10 ** 9)
		for a in sorted(nums):
			if prev != -1:
				diff = min(diff, abs(a - prev))
			prev = a
		return diff


from math import inf

class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		diff = inf
		for x in range(len(nums) - 1):
			diff = min(diff, nums[x + 1] - nums[x])
		return diff


class Solution:

	def minimum_difference(self, arr):
		arr.sort()
		diff = 9999
		for i in range(len(arr) - 1):
			x = arr[i + 1] - arr[i]
			if x < diff:
				diff = x
		return diff


class Solution:

	def minimum_difference(self, nums):
		mindiff = 99999
		nums = sorted(nums)
		for i in range(len(nums)):
			if i != len(nums) - 1 and nums[i + 1] - nums[i] < mindiff:
				mindiff = nums[i + 1] - nums[i]
		return mindiff


class Solution:

	def minimum_difference(self, nums):
		min_diff = 10000000000000
		sorted_nums = sorted(nums)
		for i in range(len(nums) - 1):
			min_diff = min(min_diff, abs(sorted_nums[i] - sorted_nums[i + 1]))
		return min_diff


import sys

class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		res = sys.maxsize
		for i in range(1, len(nums)):
			res = min(res, nums[i] - nums[i - 1])
		return res


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		arr = []
		n = len(nums)
		for i in range(n - 1):
			arr.append(nums[i + 1] - nums[i])
		arr.sort()
		return abs(arr[0])


class Solution:

	def minimum_difference(self, nums):
		if len(nums) <= 1:
			return 0
		res = float('inf')
		nums.sort()
		for i in range(len(nums) - 1):
			res = min(res, nums[i + 1] - nums[i])
		return res


class Solution:

	def minimum_difference(self, nums):
		l = nums
		res = float('inf')
		n = len(l)
		if n <= 1:
			return res
		l.sort()
		(a, b) = (-1, -1)
		for i in range(n - 1):
			if res > l[i + 1] - l[i]:
				(a, b) = (i, i + 1)
				res = l[i + 1] - l[i]
		return res


class Solution:

	def minimum_difference(self, nums):
		n = len(nums)
		nums.sort()
		inf = 100000
		for i in range(1, n):
			inf = min(inf, nums[i] - nums[i - 1])
		return inf


class Solution:

	def minimum_difference(self, nums):
		l = sorted(nums)
		temp = []
		for i in range(0, len(l) - 1):
			temp.append(abs(l[i + 1] - l[i]))
		return min(temp)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		n = len(nums)
		min_diff = 1000000000
		for i in range(1, n):
			min_diff = min(min_diff, nums[i] - nums[i - 1])
		return min_diff


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		count = 1000000
		for i in range(len(nums) - 1):
			if nums[i + 1] - nums[i] < count:
				count = nums[i + 1] - nums[i]
		return count


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		minimum = float('inf')
		for i in range(len(nums) - 1):
			if nums[i + 1] - nums[i] < minimum:
				minimum = nums[i + 1] - nums[i]
		return minimum


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		diff = 100000000.0
		for i in range(len(nums) - 1):
			if abs(nums[i] - nums[i + 1]) < diff:
				diff = abs(nums[i] - nums[i + 1])
		return diff


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		Min_diff = 9999999
		for i in range(1, len(nums)):
			d = nums[i] - nums[i - 1]
			Min_diff = min(Min_diff, d)
		return Min_diff


class Solution:

	def minimum_difference(self, nums):
		nums = sorted(nums)
		k = max(nums)
		if len(nums) > 2:
			for i in range(0, len(nums) - 1):
				if k > abs(nums[i] - nums[i + 1]):
					k = abs(nums[i] - nums[i + 1])
			return k
		elif len(nums) == 1:
			return nums[0]
		else:
			return nums[1] - nums[0]


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mindiff = 100000
		for i in range(n - 1):
			diff = nums[i + 1] - nums[i]
			mindiff = min(mindiff, diff)
		return mindiff


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mn = 9999999999
		for i in range(len(nums) - 1):
			ans = abs(nums[i] - nums[i + 1])
			mn = min(ans, mn)
		return mn


import sys

class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		n = len(nums)
		mini = sys.maxsize
		for i in range(0, n - 1):
			if nums[i + 1] - nums[i] < mini:
				mini = nums[i + 1] - nums[i]
		return mini


class Solution:

	def minimum_difference(self, nums):
		n = len(nums)
		nums.sort()
		diff = []
		for i in range(n - 1):
			diff.append(nums[i + 1] - nums[i])
		return min(diff)


class Solution:

	def minimum_difference(self, nums):
		s = sorted(nums)
		res = 99999999999
		for i in range(1, len(s)):
			res = min(s[i] - s[i - 1], res)
		return res


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		diff = float('inf')
		for i in range(n - 1):
			if abs(nums[i + 1] - nums[i]) < diff:
				diff = abs(nums[i + 1] - nums[i])
		return diff


import sys

class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		min = sys.maxsize
		for i in range(0, len(nums) - 1):
			if min > abs(nums[i] - nums[i + 1]):
				min = abs(nums[i] - nums[i + 1])
		return min


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		s = []
		for i in range(1, len(nums)):
			s.append(nums[i] - nums[i - 1])
		return min(s)


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		l = 100000000000000000
		for i in range(1, len(nums)):
			l = min(l, abs(nums[i - 1] - nums[i]))
		return l


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		d = 999999999999
		for i in range(len(nums) - 1):
			if nums[i + 1] - nums[i] < d:
				d = nums[i + 1] - nums[i]
		return d


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		mini = 123124
		for i in range(0, len(nums) - 1):
			if nums[i + 1] - nums[i] < mini:
				mini = nums[i + 1] - nums[i]
		return mini


class Solution:

	def minimum_difference(self, nums):
		l = []
		ans = float('inf')
		from bisect import bisect_right
		for i in nums:
			k = bisect_right(l, i)
			if 0 <= k < len(l):
				ans = min(ans, abs(l[k] - i))
			if 0 <= k - 1 < len(l):
				ans = min(ans, abs(l[k - 1] - i))
			l.insert(k, i)
		return ans


class Solution:

	def minimum_difference(self, nums):
		nums.sort()
		min = abs(nums[0] - nums[1])
		for i in range(0, n - 1):
			if nums[i + 1] - nums[i] < min:
				min = nums[i + 1] - nums[i]
		return min