-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets - Karla #16
base: master
Are you sure you want to change the base?
Sockets - Karla #16
Conversation
@@ -1,6 +1,28 @@ | |||
# 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
No description provided.