lib/array_intersection.rb
# O(n) time and space complexities
O(n) time and space complexities
O ( n ) time and space complexities
def intersection(list1, list2)
  array = list1.concat(list2)
  hash = {}
  result = []
  array.each do |item|
    if hash[item].nil?
      hash[item] = true
    else
      result << item
    end
  end
  return result
end
def intersection ( list1 , list2 ) array = list1 . concat ( list2 ) hash = { } result = [ ] array . each do | item | if hash [ item ] . nil? hash [ item ] = true else result << item end end return result end
O(n) time and space complexities
O ( n ) time and space complexities
list1
<not_specific>
list2
<not_specific>