We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
fromcollectionsimportCounterdefhappy_counter(array,A,B):array_count=Counter(array)#Counthowmanytimeseachintegerisrepeatedinarrayrepeated=0forintegerinarray_count.keys():# Only considering repeated terms, check if they are in A or Bvalue=array_count[integer]-1ifvalue!=0:ifintegerinA:repeated+=valueelifintegerinB:repeated-=value# Non repeated terms are accounted for using the intersection methodnon_repeated=len(A.intersection(set(array)))-len(B.intersection(set(array)))returnnon_repeated+repeatedif__name__=='__main__':n,m=list(map(int,input().split()))array=list(map(int,input().split()))A=set(map(int,input().split()))B=set(map(int,input().split()))print(happy_counter(array,A,B))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
No Idea!
You are viewing a single comment's thread. Return to all comments →