You are given an array Arr of size N. Find the sum of distinct elements in an array.
Example 1:
Input:
N = 5
Arr[] = {1, 2, 3, 4, 5}
Output: 15
Explanation: Distinct elements are 1, 2, 3
4, 5. So sum is 15.
Example 2:
Input:
N = 5
Arr[] = {5, 5, 5, 5, 5}
Output: 5
Explanation: Only Distinct element is 5.
So sum is 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSum() which takes the array of integers arr and n as parameters and returns an integer denoting the answer.
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N*logN)
Constraints:
1 ≤ N ≤ 10^{7}
0 ≤ A[i] ≤ 10^{3}

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N*logN)
Expected Auxiliary Space: O(N*logN)

Starter code:
#User function Template for python3
class Solution:
	
	def findSum(self,arr, n):
		# code here

Solutions:
class Solution:

	def findSum(self, arr, n):
		s = set(arr)
		a = list(s)
		return sum(a)


class Solution:

	def findSum(self, arr, n):
		return sum(set(arr))


class Solution:

	def findSum(self, arr, n):
		a = set(arr)
		b = sum(a)
		return b


class Solution:

	def findSum(self, arr, n):
		b = set(arr)
		summ = 0
		for i in b:
			summ += i
		return summ


class Solution:

	def findSum(self, arr, n):
		d = set(arr)
		s = 0
		for i in d:
			s += i
		return s


class Solution:

	def findSum(self, arr, n):
		x = set(arr)
		y = list(x)
		return sum(y)


class Solution:

	def findSum(self, arr, n):
		a = list(set(arr))
		s = 0
		for i in a:
			s = s + i
		return s


class Solution:

	def findSum(self, arr, n):
		dic = {}
		total = 0
		for i in arr:
			if i in dic:
				pass
			else:
				total += i
				dic[i] = 1
		return total


import collections

class Solution:

	def findSum(self, arr, n):
		arr1 = collections.Counter(arr)
		return sum(arr1.keys())


class Solution:

	def findSum(self, arr, n):
		a = set()
		sum = 0
		for i in range(n):
			if arr[i] not in a:
				a.add(arr[i])
				continue
		x = list(a)
		for j in range(len(x)):
			sum += x[j]
		return sum


class Solution:

	def findSum(self, arr, n):
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		return sum(d.keys())


class Solution:

	def findSum(self, arr, n):
		sum = 0
		d = {}
		for i in range(len(arr)):
			if d.get(arr[i], -1) == -1:
				sum += arr[i]
				d[arr[i]] = 1
		return sum


class Solution:

	def findSum(self, arr, n):
		sum = 0
		s = set(arr)
		s1 = list(s)
		for i in range(len(s1)):
			sum += s1[i]
		return sum


class Solution:

	def findSum(self, arr, n):
		l1 = list(set(arr))
		return sum(l1)


class Solution:

	def findSum(self, arr, n):
		arr = set(arr)
		sum = 0
		for i in arr:
			sum = sum + i
		return sum


class Solution:

	def findSum(self, arr, n):
		a = {'a', 'b'}
		for i in arr:
			a.add(i)
		sum = 0
		for i in a:
			if isinstance(i, int):
				sum += i
		return sum


class Solution:

	def findSum(self, arr, n):
		data = set({})
		sum = 0
		for i in range(n):
			if arr[i] in data:
				continue
			else:
				data.add(arr[i])
				sum = sum + arr[i]
		return sum


class Solution:

	def findSum(self, arr, n):
		times = {}
		total = 0
		for num in arr:
			total += num
			if num not in times:
				times[num] = 1
			else:
				total -= num
				times[num] += 1
		return total


class Solution:

	def findSum(self, arr, n):
		arr = list(set(arr))
		sumi = 0
		for i in arr:
			sumi += i
		return sumi


class Solution:

	def findSum(self, arr, n):
		d = {}
		su = 0
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in d:
			su += i
		return su


class Solution:

	def findSum(self, arr, n):
		a = set(arr)
		result = 0
		for i in a:
			result = result + i
		return result


class Solution:

	def findSum(self, arr, n):
		freq = {}
		for i in arr:
			try:
				freq[i] = freq.get(i, 0) + 1
			except:
				freq[i] = 1
		sum = 0
		for k in freq.keys():
			sum += k
		return sum


class Solution:

	def findSum(self, arr, n):
		l = list(set(arr))
		return sum(l)


class Solution:

	def findSum(self, arr, n):
		set_arr = set(arr)
		list_arr = list(set_arr)
		return sum(list_arr)


class Solution:

	def findSum(self, arr, n):
		l = []
		arr.sort()
		for i in range(n - 1):
			if arr[i] != arr[i + 1]:
				l.append(arr[i])
		l.append(arr[-1])
		return sum(l)


class Solution:

	def findSum(self, arr, n):
		a = set(arr)
		b = list(a)
		sum = 0
		for i in range(len(b)):
			sum += b[i]
		return sum


class Solution:

	def findSum(self, arr, n):
		k = sum(list(set(arr)))
		return k


class Solution:

	def findSum(self, arr, n):
		set_arr = set(arr)
		total = 0
		for item in set_arr:
			total += item
		return total


class Solution:

	def findSum(self, arr, n):
		s = set()
		for i in arr:
			s.add(i)
		return sum(s)


class Solution:

	def findSum(self, arr, n):
		sum = 0
		h = {}
		for i in arr:
			if i not in h:
				h[i] = 1
				sum = sum + i
			else:
				h[i] = h[i] + 1
		return sum


class Solution:

	def findSum(self, a, n):
		return sum(set(a))


class Solution:

	def findSum(self, arr, n):
		freq = {}
		for i in range(0, n):
			if arr[i] in freq:
				i += 1
			else:
				freq[arr[i]] = 1
		lst = list(freq.keys())
		return sum(lst)


class Solution:

	def findSum(self, arr, n):
		s = set()
		for i in arr:
			s.add(i)
		ans = 0
		for i in s:
			ans += i
		return ans


class Solution:

	def findSum(self, arr, n):
		arr.sort()
		k = [arr[0]]
		for i in range(1, n):
			if arr[i] > arr[i - 1]:
				k.append(arr[i])
			elif arr[i] == arr[i - 1]:
				pass
		s = sum(k)
		return s


class Solution:

	def findSum(self, arr, n):
		ar = list(set(arr))
		return sum(ar)


class Solution:

	def findSum(self, arr, n):
		d1 = {}
		for i in arr:
			if i in d1:
				d1[i] += 1
			else:
				d1[i] = 1
		l1 = list(d1.keys())
		return sum(l1)


class Solution:

	def findSum(self, arr, n):
		k = set(arr)
		sum1 = 0
		for i in k:
			sum1 = sum1 + i
		return sum1


class Solution:

	def findSum(self, arr, n):
		x = set(arr)
		y = list(x)
		sum = 0
		for i in range(len(x)):
			sum = sum + y[i]
		return sum


class Solution:

	def findSum(self, arr, n):
		s = set(arr)
		sum = 0
		for num in s:
			sum += num
		return sum