daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Dec 12th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def common_array_elements(a,b,c):
  3.     da = {}
  4.     db = {}
  5.     dc = {}
  6.    
  7.     for i in range(0, len(a)):
  8.         da[a[i]]=0
  9.     for i in range(0, len(b)):
  10.         db[b[i]]=0
  11.     for i in range(0, len(c)):
  12.         dc[c[i]]=0
  13.    
  14.     for i in range(0, len(a)):
  15.         da[a[i]]+=1
  16.     for i in range(0, len(b)):
  17.         db[b[i]]+=1
  18.     for i in range(0, len(c)):
  19.         dc[c[i]]+=1
  20.    
  21.     suma = 0
  22.     for key in da:
  23.         if key in db and key in dc:
  24.             suma += key * min(da[key], db[key], dc[key])
  25.     return suma
  26.    
  27. a = [ 1, 2, 2, 3 ];
  28. b = [ 5, 3, 2, 2 ];
  29. c = [ 7, 3, 2, 2 ];
  30.  
  31. print(common_array_elements(a, b, c))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top