Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/array_intersection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Returns a new array to that contains elements in the intersection of the two input arrays
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(m*n), where m is size of first array and n is the size of second array
# Space complexity: O(m), where m is the size of the smallest array
def intersection(array1, array2)
raise NotImplementedError
result = []

if array1 == nil || array2 == nil
result = []
else
array1.each do |n|
array2.each do |m|
if n == m
result << n
end
end
end
end
return result
end