Skip to content

Conversation

@kguadron
Copy link

No description provided.

# Returns a new array to that contains elements in the intersection of the two input arrays
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n + m) where n and m are the lengths of the two array inputs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will both arrays always be equal in length?

elsif array1.length < array2.length
larger = array2
smaller = array1
elsif array1.length >= array2.length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice you used >= but not <= on line 8 for comparison. What's your thinking behind this choice?


hash_table = {}
smaller.each do |num|
hash_table[num] = 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if two keys are the same?

combined = []
larger.each do |num|
if hash_table.include? num
combined << num

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if anything is being combined here. Perhaps matches might be a better variable name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants