# Task

**_Given_** an *array/list [] of n integers* , *find maximum triplet sum in the array* **_Without duplications_**   .
___

# Notes :

* **_Array/list_** size is *at least 3* .

* **_Array/list_** numbers could be a *mixture of positives , negatives and zeros* .

* **_Repetition_** of numbers in *the array/list could occur* , So **_(duplications are not included when summing)_**.
___
# Input >> Output Examples 

## **_Explanation_**:

* As the **_triplet_** that *maximize the sum* **_{6,8,3}_** in order , **_their sum is (17)_** 

* *Note* : **_duplications_** *are not included when summing* , **(i.e) the numbers added only once** .
___
## **_Explanation_**:

* As the **_triplet_** that *maximize the sum* **_{8, 6, 4}_** in order , **_their sum is (18)_** , 
* *Note* : **_duplications_** *are not included when summing* , **(i.e) the numbers added only once** .
___
## **_Explanation_**:

* As the **_triplet_** that *maximize the sum* **_{12 , 29 , 0}_** in order , **_their sum is (41)_** , 
* *Note* : **_duplications_** *are not included when summing* , **(i.e) the numbers added only once** .
___
# [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 max_tri_sum(numbers):
	

Solutions:
def max_tri_sum(numbers):
	return sum(sorted(set(numbers))[-3:])


from heapq import nlargest

def max_tri_sum(numbers):
	return sum(nlargest(3, set(numbers)))


def max_tri_sum(n):
	return sum(sorted(set(n))[-3:])


def max_tri_sum(nums):
	return sum(sorted(set(nums))[-3:])


max_tri_sum = lambda l: sum(sorted(set(l))[-3:])


def max_tri_sum(numbers):
	sorted_n = sorted(numbers, reverse=True)
	triplet = [sorted_n[0]]
	count = 1
	for n in sorted_n[1:]:
		if count == 3:
			break
		if n not in triplet:
			triplet = triplet + [n]
			count += 1
	return sum(triplet)


from typing import List

def max_tri_sum(numbers: List[int]) -> int:
	(m1, m2, m3) = sorted(numbers[:3])
	for n in numbers[3:]:
		if n > m1:
			if n > m2:
				if n > m3:
					(m1, m2, m3) = (m2, m3, n)
				elif n != m3:
					(m1, m2) = (m2, n)
			elif n != m2:
				m1 = n
	return m1 + m2 + m3


def max_tri_sum(numbers):
	sorted_numbers = sorted(set(numbers), reverse=True)
	return sum(sorted_numbers[:3])


def max_tri_sum(numbers):
	return sum(sorted([x for x in set(numbers)])[-3:])


def max_tri_sum(numbers):
	n = sorted(list(set(numbers)), reverse=True)
	return sum(n[:3])


import itertools

def max_tri_sum(numbers):
	return max((sum(i) for i in itertools.combinations(set(numbers), 3)))


def max_tri_sum(numbers):
	sorted_set = list(set(sorted(numbers)))
	sorted_list = sorted(sorted_set)
	return sum(sorted_list[-3:])


def max_tri_sum(numbers):
	return sum(__import__('heapq').nlargest(3, set(numbers)))


def max_tri_sum(numbers):
	ls = sorted(list(set(numbers)))
	return ls[-1] + ls[-2] + ls[-3]


def max_tri_sum(numbers):
	s = sorted(set(numbers), reverse=True)
	return s[0] + s[1] + s[2]


from functools import reduce
from operator import add

def max_tri_sum(numbers):
	numbers = list(dict.fromkeys(numbers))
	sort_num = sorted(numbers)
	return reduce(add, sort_num[-3:])


def max_tri_sum(numbers):
	n = list(set(numbers))
	n.sort(reverse=True)
	return sum(n[:3])


def max_tri_sum(numbers):
	arr = list(set(numbers))
	a = sorted(arr, reverse=True)
	sum = a[0] + a[1] + a[2]
	return sum


def max_tri_sum(numbers):
	a = []
	z = set(numbers)
	v = list(z)
	v.sort(reverse=True)
	b = v[0:3]
	s = sum(b)
	return s


def max_tri_sum(numbers):
	num = sorted(list(set(numbers)))
	return sum(num[len(num) - 3:])


def max_tri_sum(N):
	S = set(N)
	s = 0
	for i in range(3):
		s += max(S)
		S.remove(max(S))
	return s


def max_tri_sum(numbers):
	numbers = list(set(numbers))
	max1 = max(numbers)
	numbers.remove(max1)
	max2 = max(numbers)
	numbers.remove(max2)
	max3 = max(numbers)
	numbers.remove(max3)
	return max1 + max2 + max3


def max_tri_sum(numbers):
	numberlist = []
	accumulator = 0
	for eachnumber in numbers:
		if eachnumber in numberlist:
			continue
		else:
			numberlist.append(eachnumber)
	numberlist.sort()
	for eachnumber in numberlist[-3:]:
		accumulator = accumulator + eachnumber
	return accumulator


def max_tri_sum(numbers):
	count = 0
	answer = 0
	numbers = set(numbers)
	while count < 3:
		answer += max(numbers)
		numbers.remove(max(numbers))
		count += 1
	return answer


def max_tri_sum(numbers):
	x = set()
	for c in numbers:
		x.add(c)
	s = list(x)
	s = sorted(s, reverse=True)
	return sum(s[:3])


def max_tri_sum(numbers):
	n = list(set(numbers))
	n.sort(reverse=1)
	return sum(n[:3])


def max_tri_sum(numbers):
	return sum(sorted(set(numbers), reverse=True)[0:3])


def max_tri_sum(numbers):
	return sum((i for i in sorted(set(numbers))[-3:]))


def max_tri_sum(numbers):
	a = sorted(set(numbers), reverse=True)
	return sum(a[:3])


def max_tri_sum(numbers: list):
	numbers = set(numbers)
	s = 0
	for _ in range(3):
		i = max(numbers)
		s += i
		numbers.remove(i)
	return s


def max_tri_sum(numbers):
	print(numbers)
	a = sorted([i for i in set(numbers)])
	return a[-1] + a[-2] + a[-3]


def max_tri_sum(numbers):
	unique = list(set(numbers))
	unique.sort(reverse=True)
	return unique[0] + unique[1] + unique[2]


def max_tri_sum(numbers):
	answer = []
	numbers.sort(reverse=True)
	for MaxNumbers in numbers:
		if MaxNumbers not in answer and len(answer) < 3:
			answer.append(MaxNumbers)
		elif answer == 3:
			break
		print(answer)
	return sum(answer)


max_tri_sum = lambda nums: sum(sorted(list(set(nums)))[-3:])


def max_tri_sum(numbers):
	lst = sorted(list(set(numbers)))
	return sum(lst[len(lst) - 3:])


def max_tri_sum(numbers):
	snumbers = set(numbers)
	snumbersl1 = list(snumbers)
	snumbersl1 = sorted(snumbersl1)
	print(snumbers)
	snumbersl = []
	n = 3
	while n > 0:
		maxn = max(snumbersl1)
		snumbersl.append(maxn)
		n -= 1
		snumbersl1.pop()
	return sum(snumbersl)


def max_tri_sum(numbers):
	new_num = set(numbers)
	max_sum = list()
	for i in range(3):
		max_sum.append(max(new_num))
		new_num.remove(max(new_num))
	return sum(max_sum)


def max_tri_sum(numbers):
	lst = [i for i in sorted(set(numbers), reverse=True)]
	return sum(lst[:3])


def max_tri_sum(numbers):
	num = list(set(numbers))
	num.sort(reverse=True)
	return sum(num[0:3])


def max_tri_sum(numbers):
	new_n = list(set(numbers))
	r1 = max(new_n)
	new_n.remove(r1)
	r2 = max(new_n)
	new_n.remove(r2)
	r3 = max(new_n)
	new_n.remove(r3)
	return r1 + r2 + r3


def max_tri_sum(num):
	return sum(sorted(set(num), reverse=True)[:3])


from heapq import nlargest
max_tri_sum = lambda lst: sum(nlargest(3, set(lst)))


def max_tri_sum(numbers):
	setnum = set(numbers)
	lst = list(setnum)
	lst_sort = sorted(lst)
	return sum(lst_sort[-3:])


from itertools import combinations

def max_tri_sum(n):
	l = set(n)
	return max([x + y + z for (x, y, z) in list(combinations(l, 3))])


def merge(a, b):
	ac = 0
	bc = 0
	ra = []
	while True:
		if ac < len(a) and bc < len(b):
			if a[ac] > b[bc]:
				ra.append(a[ac])
				ac = ac + 1
			else:
				ra.append(b[bc])
				bc = bc + 1
		elif ac < len(a):
			ra.append(a[ac])
			ac = ac + 1
		elif bc < len(b):
			ra.append(b[bc])
			bc = bc + 1
		else:
			break
	return ra

def mysort(arr):
	if len(arr) < 2:
		return arr
	else:
		mid = len(arr) // 2
		part1 = mysort(arr[:mid])
		part2 = mysort(arr[mid:])
		return merge(part1, part2)

def max_tri_sum(numbers):
	nodup = {}
	for x in numbers:
		nodup[x] = 0
	nodup = list(nodup.keys())
	nodup = mysort(nodup)
	i = 0
	s = 0
	while i < 3:
		s = s + nodup[i]
		i = i + 1
	return s


def max_tri_sum(arr):
	arr = list(reversed(sorted(set(arr))))
	total = 0
	for i in range(0, 3):
		total += arr[i]
	return total


def max_tri_sum(numbers):
	numbers.sort(reverse=True)
	max_numbers = list(dict.fromkeys(numbers))
	max_sum = sum(max_numbers[:3])
	return max_sum


from heapq import nlargest

def max_tri_sum(numbers):
	assert len(numbers) >= 3
	return sum(nlargest(3, set(numbers)))


def max_tri_sum(numbers):
	return sum(sorted([item for item in set(numbers)])[-3:])


def max_tri_sum(numbers):
	lst = list(set(numbers))
	lst.sort()
	return sum(lst[-1:-4:-1])


def max_tri_sum(numbers):
	maximums = []
	while len(maximums) < 3:
		if max(numbers) not in maximums:
			maximums.append(max(numbers))
		else:
			numbers.remove(max(numbers))
	return sum(maximums)


def max_tri_sum(numbers):
	maxes = [max(numbers)]
	maxless = []
	for num in numbers:
		if num not in maxless and num not in maxes:
			maxless.append(num)
	maxes.append(max(maxless))
	maxless = []
	for num in numbers:
		if num not in maxless and num not in maxes:
			maxless.append(num)
	maxes.append(max(maxless))
	return sum(maxes)


def max_tri_sum(numbers):
	z = set(numbers)
	x = sorted(z, reverse=True)
	return sum(x[0:3])


def max_tri_sum(numbers):
	s = []
	for i in numbers:
		if i not in s:
			s.append(i)
	a = sorted(s)[-1]
	b = sorted(s)[-2]
	c = sorted(s)[-3]
	return a + b + c


def max_tri_sum(numbers):
	newList = []
	newList = list(set(numbers))
	newList.sort(reverse=True)
	result = newList[0] + newList[1] + newList[2]
	return result


def max_tri_sum(numbers):
	a = set(numbers)
	b = max(a)
	c = a.remove(b)
	d = max(a)
	e = a.remove(d)
	f = max(a)
	return b + d + f


max_tri_sum = lambda a: sum(sorted(list(set(a)))[-3:])


def max_tri_sum(numbers):
	max = 0
	sum = 0
	i = 0
	result = []
	while i < 3:
		max = -9999999999
		for item in numbers:
			if item >= max:
				max = item
		if max not in result:
			result.append(max)
		for item in numbers:
			if item == max:
				numbers.remove(max)
		i += 1
	for item in result:
		sum += item
	return sum


def max_tri_sum(numbers):
	a = sorted(set(numbers))
	return sum(a[-3::1])


def max_tri_sum(numbers):
	ans = []
	numbers.sort(reverse=True)
	for x in numbers:
		if x not in ans:
			ans.append(x)
	return sum(ans[:3])


def max_tri_sum(numbers):
	test_list = list(set(numbers))
	sorted_list = sorted(test_list)
	return sum(sorted_list[-3:])


def max_tri_sum(a):
	a.sort()
	q = []
	[q.append(i) for i in a if i not in q]
	return sum(q[-3:])


def max_tri_sum(numbers):
	c = sorted(set(numbers), reverse=True)
	return sum(c[:3])


def max_tri_sum(numbers):
	x = sorted(set(numbers))
	l = []
	for n in reversed(x):
		if len(l) <= 2:
			l.append(n)
	return sum(l)


def max_tri_sum(numbers):
	num_set = list(set(numbers))
	sorted_nums = sorted(num_set, reverse=True)
	return sum(sorted_nums[0:3])


import sys

def max_tri_sum(numbers):
	numbers = sorted(list(set(numbers)))
	return sum(numbers[-3:])


def max_tri_sum(numbers):
	numbers = set(numbers)
	numbers = list(numbers)
	n1 = numbers.pop(numbers.index(max(numbers)))
	n2 = numbers.pop(numbers.index(max(numbers)))
	n3 = numbers.pop(numbers.index(max(numbers)))
	return sum((n1, n2, n3))


def max_tri_sum(numbers):
	l = []
	l2 = []
	for i in numbers:
		if i not in l:
			l.append(i)
	for i in range(3):
		l2.append(max(l))
		l.remove(max(l))
	return sum(l2)


def max_tri_sum(numbers):
	return sum([number for number in sorted(list(set(numbers)))[-1:-4:-1]])


def max_tri_sum(numbers):
	return sum(sorted(list(dict.fromkeys(numbers)))[-3:])


def max_tri_sum(arr):
	return sum(sorted(set(arr))[-3:])


def max_tri_sum(numbers):
	new_list = set(numbers)
	third_new_list = sorted(new_list, reverse=True)[:3]
	return sum(third_new_list)


def max_tri_sum(numbers):
	lst = sorted(numbers[:3])
	for i in numbers[3:]:
		if i > lst[0]:
			if i not in lst:
				for x in range(len(lst)):
					if i < lst[x]:
						del lst[0]
						lst.insert(x - 1, i)
						break
					elif i > lst[2]:
						del lst[0]
						lst.append(i)
						break
	return sum(lst)


def max_tri_sum(numbers):
	numbers_lst = []
	for i in numbers:
		if i not in numbers_lst:
			numbers_lst.append(i)
			numbers_lst.sort()
	return sum(numbers_lst[-3:])


def max_tri_sum(n):
	lst = sorted(set(n))[-3:]
	return sum([int(i) for i in lst])


def max_tri_sum(numbers):
	return sum(sorted(set(numbers), key=None, reverse=True)[:3])


def max_tri_sum(n):
	n = list(set(n))
	n.sort(reverse=True)
	return sum(n[0:3])


def max_tri_sum(numbers):
	x = []
	for i in numbers:
		if i not in x:
			x.append(i)
	x = sorted(x)
	return sum(x[-3:])


def max_tri_sum(numbers):
	no_duplicates = set(numbers)
	ordered = sorted(no_duplicates)
	return sum(ordered[-3:])


def max_tri_sum(numbers):
	x = sorted(list(set(numbers)), reverse=True)
	return sum(x[:3])


def max_tri_sum(numbers):
	uniq = set(numbers)
	return sum([max(uniq), max(uniq - {max(uniq)}), max(uniq - {max(uniq)} - {max(uniq - {max(uniq)})})])


def max_tri_sum(numbers):
	sum = 0
	numbers = set(numbers)
	num = list(numbers)
	num = sorted(num)
	for i in sorted(num[-3:]):
		sum = i + sum
	return sum


def max_tri_sum(numbers):
	l = sorted(set(numbers), reverse=True)
	sum = 0
	for i in range(3):
		sum += l[i]
	return sum


from itertools import combinations

def max_tri_sum(numbers):
	return max([sum(x) for x in list(combinations(set(numbers), 3))])


def max_tri_sum(numbers):
	numbers = set(numbers)
	max_sum = 0
	for i in range(3):
		n = max(numbers)
		numbers.remove(n)
		max_sum += n
	return max_sum