-
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 - Erica #26
base: master
Are you sure you want to change the base?
Sockets - Erica #26
Conversation
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.
Good code.
What other solutions did you consider? This is the brute-force way of solving the problem, and it works, but time complexity is less than ideal. Can you do better without sacrificing space complexity? You should at least discuss in your comments, even if you don't code another solution.
def intersection(array1, array2) | ||
raise NotImplementedError | ||
return [] if array1 == nil || array2 == nil |
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.
nil might be more appropriate if one of the input arrays is nil. The problem description doesn't specify, so your choice is still valid.
return [] if array1 == nil || array2 == nil | ||
|
||
i = 0 | ||
inter_array = [] |
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.
Not a great variable name. Choose a name that tells the reader what it's for.
# Time complexity: ? | ||
# Space complexity: ? | ||
# Time complexity: O(n*m), where n is the number of elements in array1 and m is the number of elements in array2 | ||
# Space complexity: O(n), where n is less than m |
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.
Except n is not necessarily less than m. A more accurate statement would be: O(min(n,m)). Also, not that that's the worst case; when one array is a subset of the other. The typical case will be smaller.
No description provided.