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.
+ 0 comments n, m = map(int,input().split()) l = list(map(int,input().split())) set_A = set(map(int, input().split())) set_B = set(map(int, input().split())) happiness = 0 # What happens if i is present in both the sets? # What about duplicate elements in array, should we consider all the occurences? for i in l: if i in set_A: happiness+=1 elif i in set_B: happiness-=1 print(happiness)
+ 0 comments Here the catch is array of integers should be list not set for taking commen values as well
n = set(input().split()) set1 = list(map(int, input().split())) A = set(map(int, input().split())) B = set(map(int, input().split())) print(sum([1 for i in set1 if i in A ])-sum([1 for i in set1 if i in B]))
+ 0 comments My solution for Python 3. We have to tell Python that A & B are sets. It can not understand that if they're lists, and will spend a lot of time for processing them as lists...
nm = [int(i) for i in input().split()] n = [int(i) for i in input().split()] A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] happiness = 0 As = set(A) Bs = set(B) for num in n: if num in As: happiness += 1 else: if num in Bs: happiness -= 1 print(happiness)
+ 0 comments my solution, i wanted to practice function and use the contraints in the problem
# Enter your code here. Read input from STDIN. Print output to STDOUT def happiness(set1: set , set2: set, array: list): happy = 0 if n >= 1 and n <= 10 ** 5 and m >= 1 and m <= 10 ** 5: for i in array: if 1 <= i <= 10**9: if i in set1: happy += 1 elif i in set2: happy -= 1 return(happy) if __name__ == '__main__': n,m = map(int, input().split()) arr = list(map(int, input().split())) setA = set(map(int, input().split())) setB = set(map(int, input().split())) result= happiness(setA, setB, arr) print(result)
+ 1 comment This solution doesn't work?
ints = input().split() n_int = input().split() A = input().split() B = input().split() happiness = set(n_int).intersection(set(A)) unhappiness = set(n_int).intersection(set(B)) result = len(happiness) - len(unhappiness) print(result)
Load more conversations
Sort 1304 Discussions, By:
Please Login in order to post a comment