Please Login in order to post a comment
This is passing. The key is to assign A and B to a set in order to run the computation quickly enough to pass the tests.
n, m = map(int, input().split()) arr = map(int, input().split()) set_a = set(map(int, input().split())) set_b = set(map(int, input().split())) happiness = 0 for e in arr: if e in set_a: happiness += 1 elif e in set_b: happiness -= 1 print(happiness)
Can anyone tell me why this code is only passing some of the test cases and not all ?
n, m = map(int, input().split()) arr = set(map(int, input().split())) s1 = set(map(int, input().split())) s2 = set(map(int, input().split()))
posititve = s1.intersection(arr) negative = s2.intersection(arr)
happines = len(posititve)-len(negative) print(happines)
can anyone plse tell me why my submission is failing
arr=list(input().split()) set_A=set(input().split()) set_B=set(input().split()) happiness=0 for i in arr: if i in set_A: happiness+=1
elif i in set_B: happiness-=1 else: continue
print(happiness)
'''Try out with this one''' std_inp = input().split() str_array = input().split() set_a = set(input().split()) set_b = set(input().split()) happiness = 0
for i in str_array: if i in set_a: happiness += 1 elif i in set_b: happiness -= 1 else: continue print(happiness)
One-liner:
n, m = input().split() X = list(input().split()) A = set(input().split()) B = set(input().split()) print(sum([1 if x in A else -1 if x in B else 0 for x in X]))
Seems like cookies are disabled on this browser, please enable them to open this website
This is passing. The key is to assign A and B to a set in order to run the computation quickly enough to pass the tests.
Can anyone tell me why this code is only passing some of the test cases and not all ?
n, m = map(int, input().split()) arr = set(map(int, input().split())) s1 = set(map(int, input().split())) s2 = set(map(int, input().split()))
posititve = s1.intersection(arr) negative = s2.intersection(arr)
happines = len(posititve)-len(negative) print(happines)
can anyone plse tell me why my submission is failing
arr=list(input().split()) set_A=set(input().split()) set_B=set(input().split()) happiness=0 for i in arr: if i in set_A: happiness+=1
print(happiness)
'''Try out with this one''' std_inp = input().split() str_array = input().split() set_a = set(input().split()) set_b = set(input().split()) happiness = 0
for i in str_array: if i in set_a: happiness += 1 elif i in set_b: happiness -= 1 else: continue print(happiness)
One-liner: