-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3_3.py
31 lines (24 loc) · 707 Bytes
/
test3_3.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
#3: Time Complexity :TapeEquilibrium
from joblib import Parallel, delayed
def fn(x,A):
first = sum(A[x+1:])
second = sum(A[:x+1])
return abs(second-first)
def solution(A):
len_A = len(A)
#min_diff = 0
#result_list = []
result_list = list(map(lambda x:fn(x,A),A))
'''
result_list = Parallel(n_jobs=2,verbose=0,prefer='processes'
)(delayed(fn)(A,x) for x in range(len_A-1))
for i in range(len_A-1):
first = sum(A[i+1:])
second = sum(A[:i+1])
result_list.append(abs(second-first))
if(result_list.count(0)>0):
return(0)
'''
return min(result_list)
A = list(range(1,10000))
print(solution(A))