# Task
Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j.

If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead.


# Input/Output

`[input]` integer array `arr`

A non-empty array of positive integer.

`2 <= arr.length <= 10`

`1 <= arr[i] <= 100`

`[output]` an integer

The maximum value of `k` or `-1` if there is none.


# Example

For `arr = [1, 2, 3]`, the output should be `1`.

`1` is the only k which satisfies the given conditions.

For `arr = [1, 1, 1]`, the output should be `-1`.

`1 % k = 1` for `any k > 1`, so it's impossible to find the maximum.

For `arr = [5, 2, 8]`, the output should be `3`.

`5 % 3 == 2 % 3 == 8 % 3 == 2`

Difficulty: EASY
Starter code: def finding_k(arr):
	

Solutions:
def finding_k(arr):
	for n in range(max(arr) - 1, 0, -1):
		if len({x % n for x in arr}) == 1:
			return n
	return -1


from itertools import repeat
from functools import reduce
from operator import sub
from math import gcd

def finding_k(arr):
	return reduce(gcd, filter(None, map(sub, set(arr), repeat(min(arr)))), 0) or -1


def finding_k(arr):
	s = set(arr)
	if s == {1}:
		return -1
	for k in range(max(s), 0, -1):
		r = arr[0] % k
		if all((x % k == r for x in s)):
			return k
	return -1


finding_k = lambda a: max([k for k in range(1, max(a)) if eval('=='.join([str(z) + '%' + str(k) for z in a]))], default=-1)


def finding_k(arr):
	for i in range(max(arr) - 1, 0, -1):
		if len({j % i for j in arr}) == 1:
			return i
	return -1


finding_k = lambda a: next((i for i in range(max(a) - 1, 0, -1) if len(set([j % i for j in a])) == 1), -1)


def finding_k(arr):
	maxValue = max(arr) - min(arr)
	k = 0
	while maxValue > 0:
		if len(set(map(lambda x: x % maxValue, arr))) == 1:
			k = maxValue
			break
		maxValue -= 1
	if k:
		return k
	else:
		return -1


from functools import reduce
gcd = lambda a, b: gcd(b, a % b) if b else a
finding_k = lambda arr: reduce(lambda a, b: gcd(a, b), [abs(e - arr[0]) for e in arr]) or -1


def finding_k(arr):
	ans = []
	for i in range(1, 101):
		if len({j % i for j in arr}) == 1:
			ans.append(i)
	return max(ans) if len(ans) < 100 else -1