Skip to content

Latest commit

 

History

History
22 lines (22 loc) · 533 Bytes

File metadata and controls

22 lines (22 loc) · 533 Bytes

image solutions brute force (timeout)

def intersection(a, b):
  result = []
  for item in b:
    if item in a:
      result.append(item)
  return result

n = length of array a, m = length of array b Time: O(n*m) Space: O(min(n,m)) using set (pass)

def intersection(a, b):
  set_a = set(a)
  return [ item for item in b if item in set_a ]
n = length of array a, m = length of array b

Time: O(n+m) Space: O(n)