forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
44 lines (25 loc) · 837 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/python3
import math
import os
import random
import re
import sys
# Code to be written by user
def lonelyinteger(a):
#converting to list to eliminate the repeated elements.
b = set(a)
#length of a i.e. number of repeated elements.
n = len(a)
#if len(a) i.e. if the list has only one element return that element only.
if n == 1:
return a[0]
#else return result where result is difference between the double of sum of elements in set b and sum of elements in list a
return ((sum(b)*2 - sum(a)))
#code snippet given by Hackerrank
if _name_ == '_main_':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
a = list(map(int, input().rstrip().split()))
result = lonelyinteger(a)
fptr.write(str(result) + '\n')
fptr.close()