The following code works in a hackerrank problem: (A and B will get non repetitive and discrete data by default)
n,m = map(int,input().split())
arr = list(map(int,input().split()))
A = set(map(int,input().split()))
B = set(map(int,input().split()))
count = 0
for x in arr:
if x in A:
count+=1
if x in B:
count-=1
print(count)
But the next one shows time error in 4 test cases:
n,m = map(int,input().split())
arr = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
for x in arr:
if x in A:
count+=1
if x in B:
count-=1
print(count)
How the time complexity changed sharply in list and set and how do they work?
in setis much more efficient thanin list. For significantly large inputs, that can be significant.python time complexityreturns many SO results - maybe there is one that will suffice. Otherwise: wiki.python.org/moin/TimeComplexity