# Introduction and Warm-up (Highly recommended)

# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___

# Task

**_Given_** an **_array of integers_** , **_Find the minimum sum_** which is obtained *from summing each Two integers product* .
___

# Notes 

* **_Array/list_** *will contain* **_positives only_** . 
* **_Array/list_** *will always has* **_even size_**
___

# Input >> Output Examples

```
minSum({5,4,2,3}) ==> return (22) 
```

## **_Explanation_**:

* **_The minimum sum_** *obtained from summing each two integers product* ,  ` 5*2 + 3*4 = 22`
___

```
minSum({12,6,10,26,3,24}) ==> return (342)
```

## **_Explanation_**:

* **_The minimum sum_** *obtained from summing each two integers product* ,  ` 26*3 + 24*6 + 12*10 = 342`

___

```
minSum({9,2,8,7,5,4,0,6}) ==> return (74)
```

## **_Explanation_**:

* **_The minimum sum_** *obtained from summing each two integers product* ,  ` 9*0 + 8*2 +7*4 +6*5 = 74`

___

___
___
___

# [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers)

# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)

# [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored)
___

## ALL translations are welcomed

## Enjoy Learning !!
# Zizou

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def min_sum(arr):
	

Solutions:
def min_sum(arr):
	arr = sorted(arr)
	return sum((arr[i] * arr[-i - 1] for i in range(len(arr) // 2)))


def min_sum(arr):
	arr.sort()
	(left, right, res) = (0, len(arr) - 1, 0)
	while left < right:
		res += arr[left] * arr[right]
		left += 1
		right -= 1
	return res


def min_sum(arr):
	ans = 0
	while len(arr) > 0:
		ans += max(arr) * min(arr)
		arr.remove(max(arr))
		arr.remove(min(arr))
	return ans


def min_sum(arr):
	return sum((x * y for (x, y) in zip(sorted(arr)[::2], sorted(arr)[-1::-2])))


min_sum = lambda a: a.sort() or sum((a[i] * a[-i - 1] for i in range(len(a) // 2)))


def min_sum(arr):
	arr.sort()
	return sum((i * arr.pop() for i in arr))


def min_sum(arr):
	arr.sort()
	return sum((a * b for (a, b) in zip(arr[:len(arr) // 2], arr[::-1])))


def min_sum(arr):
	arr = sorted(arr)
	return sum([e1 * e2 for (e1, e2) in zip(arr[:len(arr) // 2], arr[::-1][:len(arr) // 2])])


def min_sum(arr):
	arr_for_sum = []
	while len(arr) > 0:
		min_elem = min(arr)
		max_elem = max(arr)
		arr_for_sum.append(min_elem * max_elem)
		arr.remove(max_elem)
		arr.remove(min_elem)
	return sum(arr_for_sum)


def min_sum(arr):
	arr = sorted(arr)
	l = len(arr) // 2
	return sum((a * b for (a, b) in zip(arr[:l], arr[l:][::-1])))


def min_sum(arr):
	sum = 0
	reduced_arr = arr
	iters = int(len(arr) / 2)
	for i in range(iters):
		sum += min(reduced_arr) * max(reduced_arr)
		reduced_arr.remove(min(reduced_arr))
		reduced_arr.remove(max(reduced_arr))
	return sum


def min_sum(arr):
	sorted_arr = sorted(arr)
	ml = len(sorted_arr) // 2
	i = 0
	sum = 0
	while i < ml:
		sum += sorted_arr[i] * sorted_arr[-i - 1]
		i += 1
	return sum


min_sum = lambda a: a.sort() or sum((x * y for (x, y) in zip(a, a[::-1]))) // 2


def min_sum(arr):
	arr.sort()
	return sum((x * y for (x, y) in zip(arr[len(arr) // 2:], arr[:len(arr) // 2][::-1])))


def min_sum(arr):
	a = sorted(arr)
	if len(a) == 0:
		return 0
	return a[0] * a[-1] + min_sum(a[1:-1])


def min_sum(arr):
	return rec(sorted(arr))

def rec(arr, n=0):
	return n if not arr else rec(arr, n + arr.pop(0) * arr.pop(-1))


def min_sum(arr):
	arr.sort()
	s = 0
	while arr:
		s += arr.pop() * arr.pop(0)
	return s


def min_sum(arr):
	john = str(sorted(arr)).replace(']', '').replace('[', '')
	juan = john.split(',')
	joe = 0
	while len(juan) > 0:
		joe += int(juan[0]) * int(juan[-1])
		juan.pop(0)
		juan.pop(-1)
	return joe


def min_sum(arr):
	ret = 0
	arr = sorted(arr)
	while arr:
		ret += arr.pop(0) * arr.pop(-1)
	return ret


def min_sum(arr):
	total = 0
	for (i, j) in zip(sorted(arr), sorted(arr, reverse=True)):
		total += i * j
	return total / 2


def min_sum(arr):
	halflig = len(arr) // 2
	arr.sort()
	return sum((arr[x] * arr[-(x + 1)] for x in range(halflig)))


min_sum = lambda arr: (lambda s: sum((v * s[-i - 1] for (i, v) in enumerate(s[:len(s) // 2]))))(sorted(arr))


def min_sum(arr):
	sum = 0
	arr.sort()
	for i in range(len(arr) // 2):
		sum += arr[i] * arr[-1 - i]
	return sum


def min_sum(arr):
	nums1 = sorted(arr)
	nums2 = sorted(arr, reverse=True)
	return sum([nums1[i] * nums2[i] for i in range(len(nums1) // 2)])


def min_sum(arr):
	arr = sorted(arr)
	n = 0
	while len(arr) > 0:
		n += arr.pop(0) * arr.pop()
	return n


def min_sum(arr):
	arr = sorted(arr)
	n = 0
	while len(arr) > 0:
		x = arr.pop(0)
		y = arr.pop()
		n += x * y
	return n


from itertools import combinations

def min_sum(arr):
	s_arr = sorted(arr)
	n = len(arr) // 2
	l = [*zip(s_arr[:n], s_arr[-1:-n - 1:-1])]
	return sum((x * y for (x, y) in l))


def min_sum(arr):
	sum_numbers = 0
	n = int(len(arr) / 2)
	for operation in range(n):
		b = max([i for i in arr])
		c = min([i for i in arr])
		v = b * c
		sum_numbers = sum_numbers + v
		arr == arr.remove(b)
		arr == arr.remove(c)
	return sum_numbers
	pass


def min_sum(a):
	a.sort()
	return sum((a[i] * a[~i] for i in range(len(a) // 2)))


def min_sum(arr):
	total = 0
	while arr:
		(m, n) = (max(arr), min(arr))
		total += arr.pop(arr.index(m)) * arr.pop(arr.index(n))
	return total


def min_sum(arr):
	total = 0
	lowest_number = int(arr[0])
	biggest_number = int(arr[0])
	while len(arr) > 0:
		for i in arr:
			if i < lowest_number:
				lowest_number = i
			elif i > biggest_number:
				biggest_number = i
		total += biggest_number * lowest_number
		print(arr)
		arr.pop(arr.index(lowest_number))
		arr.pop(arr.index(biggest_number))
		if len(arr) >= 2:
			lowest_number = int(arr[0])
			biggest_number = int(arr[0])
	return total


def min_sum(arr):
	summ = 0
	arr = sorted(arr)
	for i in range(len(arr)):
		summ += arr[i] * arr[len(arr) - 1 - i]
	return summ / 2


def min_sum(arr):
	sort_arr = sorted(arr)
	i = 0
	sum = 0
	while i < len(arr) / 2:
		sum += sort_arr[i] * sort_arr[-(i + 1)]
		i += 1
	return sum


def min_sum(arr):
	sum = 0
	a = sorted(arr)
	b = sorted(arr, reverse=True)
	for x in range(len(arr) // 2):
		sum += a[x] * b[x]
	return sum


def min_sum(arr):
	arr.sort()
	middle = len(arr) // 2
	return sum((a * b for (a, b) in zip(arr[:middle], reversed(arr[-middle:]))))


def min_sum(arr):
	prods = []
	for i in range(len(arr) // 2):
		prods.append(max(arr) * min(arr))
		arr.remove(max(arr))
		arr.remove(min(arr))
	return sum(prods)


def min_sum(arr):
	a = sorted(arr)
	sm = 0
	for i in range(len(arr) // 2):
		sm += a[i] * a[len(a) - i - 1]
	return sm


def min_sum(arr):
	arr = sorted(arr)
	arr1 = arr[::2]
	arr2 = arr[1::2][::-1]
	a = []
	for i in range(len(arr1)):
		a.append(arr1[i] * arr2[i])
	return sum(a)


def min_sum(arr):
	s = 0
	arr = sorted(arr)
	while arr:
		s = s + arr.pop(0) * arr.pop(-1)
	return s


def grab_two(arr, run_sum):
	if len(arr) == 0:
		return run_sum
	else:
		run_sum += arr[0] * arr[-1]
		return grab_two(arr[1:-1], run_sum)

def min_sum(arr):
	arr.sort()
	return grab_two(arr, 0)


def min_sum(A):
	A = sorted(A)
	l = len(A)
	return sum((e1 * e2 for (e1, e2) in zip(A[:l // 2], A[l // 2:][::-1])))


def min_sum(arr):
	m = []
	while len(arr) > 0:
		m.append(max(arr) * min(arr))
		arr.remove(max(arr))
		arr.remove(min(arr))
	return sum(m)


def min_sum(arr):
	arr = sorted(arr)
	return sum((pair[0] * pair[1] for pair in zip(arr[:len(arr) // 2], arr[len(arr) // 2:][::-1])))


def min_sum(arr):
	answer = 0
	for i in range(int(len(arr) / 2)):
		Max = max(arr)
		Min = min(arr)
		arr.remove(Max)
		arr.remove(Min)
		answer += Min * Max
	return answer


def min_sum(a):
	a.sort()
	return sum([a[x] * a[-x - 1] for x in range(len(a) // 2)])


def min_sum(arr):
	count = 0
	while len(arr) > 0:
		count += max(arr) * min(arr)
		arr.remove(max(arr))
		arr.remove(min(arr))
	return count


def min_sum(a):
	q = sorted(a)
	return sum((q[i] * q[-i - 1] for i in range(len(q) // 2)))


def min_sum(arr):
	arr = sorted(arr)
	mid = len(arr) // 2
	return sum((a * b for (a, b) in zip(arr[:mid], reversed(arr[mid:]))))


def min_sum(arr):
	toplam = 0
	while True:
		buyuk = max(arr)
		arr.remove(buyuk)
		kucuk = min(arr)
		arr.remove(kucuk)
		toplam += buyuk * kucuk
		if len(arr) == 0:
			return toplam
	pass


def min_sum(arr):
	arr_sorted = sorted(arr)
	cut = int(len(arr_sorted) / 2)
	pairs = list(zip(arr_sorted[:cut], arr_sorted[cut:][::-1]))
	return sum((a * b for (a, b) in pairs))


def min_sum(arr):
	sum = 0
	sorted_arr = sorted(arr)
	front_i = 0
	back_i = len(arr) - 1
	while front_i < back_i:
		sum += sorted_arr[front_i] * sorted_arr[back_i]
		front_i += 1
		back_i -= 1
	return sum


def min_sum(arr):
	a1 = sorted(arr, reverse=True)
	a2 = sorted(arr)
	return int(sum((x * y for (x, y) in zip(a1, a2))) / 2)


def min_sum(arr):
	sumlist = []
	while len(arr) > 0:
		if len(arr) == 1:
			sumlist.append(arr)
		else:
			sumlist.append(max(arr) * min(arr))
			arr.remove(max(arr))
			arr.remove(min(arr))
	return sum(sumlist)


def min_sum(arr):
	result = 0
	arr.sort()
	while arr:
		result += arr.pop() * arr.pop(0)
	return result


def min_sum(arr):
	return min_sum_helper(sorted(arr))

def min_sum_helper(arr):
	if len(arr) == 2:
		return arr[0] * arr[-1]
	return arr[0] * arr[-1] + min_sum_helper(arr[1:-1])


def min_sum(arr):
	arr.sort()
	return min_sum_helper(arr)

def min_sum_helper(arr):
	if len(arr) == 2:
		return arr[0] * arr[-1]
	return arr[0] * arr[-1] + min_sum_helper(arr[1:-1])


def min_sum(arr):
	(low, high) = (sorted(arr)[:len(arr) // 2], sorted(arr, reverse=True)[:len(arr) // 2])
	return sum((x * y for (x, y) in zip(low, high)))


min_sum = lambda a: sum((x * y for (x, y) in zip(list(sorted(a)[:len(a) // 2]), list(sorted(a, reverse=True)[:len(a) // 2]))))


def min_sum(arr):
	arr.sort()
	i = 0
	s = 0
	while i < len(arr) // 2:
		s += arr[i] * arr[len(arr) - 1 - i]
		i += 1
	return s


def min_sum(l):
	l = sorted(l)
	backward = reversed(l)
	forward = iter(l)
	length = len(l)
	result = 0
	for (i, (f, b)) in enumerate(zip(forward, backward)):
		if i < length / 2:
			print(f, b)
			result += f * b
	return result


def min_sum(arr):
	cunt = []
	for cum in range(len(arr) // 2):
		cunt.append(min(arr) * max(arr))
		arr.remove(min(arr))
		arr.remove(max(arr))
	return sum(cunt)


def min_sum(arr):
	arr.sort()
	list_sum = []
	while len(arr) > 0:
		min_index = 0
		max_num = arr.pop()
		min_num = arr.pop(min_index)
		min_index += 1
		list_sum.append(max_num * min_num)
	return sum(list_sum)


def min_sum(arr):
	res = []
	while arr:
		res.append(max(arr) * min(arr))
		arr.remove(max(arr))
		arr.remove(min(arr))
	return sum(res)


def min_sum(arr: list) -> int:
	sorted_arr = sorted(arr)
	arr_len_half = len(arr) // 2
	start_arr_half = sorted_arr[:arr_len_half]
	end_arr_half = sorted_arr[arr_len_half:]
	result_sum = 0
	for (start_num, end_num) in zip(start_arr_half, end_arr_half[::-1]):
		result_sum += start_num * end_num
	return result_sum