forked from adisayhi27/Hackerrank-SI
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtriple-trouble.py
47 lines (36 loc) · 949 Bytes
/
triple-trouble.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
45
46
47
## using bit manipulation
def tripleTrouble(n,ar):
ans = 0
for i in range(30):
c=0
for j in range(n):
if (checkBit(ar[j],i)==True):
c+=1
if (c%3!=0):
ans+=1<<i
print(ans)
def checkBit(n,k):
new_num= n>>k
return (new_num & 1)
m=int(input())
for i in range(m):
n = int(input())
ar = list(map(int,input().strip().split()))[:n]
tripleTrouble(n,ar)
###########################################################################################
## Using Dictionary
def tripleTrouble1(n, arr):
a = dict()
for i in range(n):
try:
a[arr[i]] += 1
except KeyError:
a[arr[i]] = 1
for key, value in a.items():
if value == 1:
print(key)
m=int(input())
for i in range(m):
n = int(input())
ar = list(map(int,input().strip().split()))[:n]
tripleTrouble1(n,ar)