-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumdbeauty.py
More file actions
39 lines (28 loc) · 910 Bytes
/
sumdbeauty.py
File metadata and controls
39 lines (28 loc) · 910 Bytes
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
class Solution:
def calcBeauty(self,n,arr, s=0, e=0, b_arr=[]):
if e == len(arr):
return sum(b_arr)
elif s > e:
return self.calcBeauty(n, arr, 0, e+1, b_arr)
else:
subarr = arr[s:e+1]
#print(subarr)
b_arr.append(self.identify(subarr))
return self.calcBeauty(n, arr, s+1, e, b_arr)
# identify beauty
def identify(self, subarr):
d = {}
for i in subarr:
d[i] = d.get(i, 0) + 1
vals = list(d.values())
return vals.count(1)
def main():
T=int(input())
while(T>0):
n=int(input())
arr=[int(x) for x in input().strip().split()]
ob=Solution()
print(ob.calcBeauty(n,arr))
T-=1
if __name__ == "__main__":
main()