Skip to content

Conversation

@paulentine
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Nice work, this is an optimal solution. The if statement lets you from a practical standpoint minimize memory usage, as you make a smaller hash.

# Returns a new array to that contains elements in the intersection of the two input arrays
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) to hash in, O(m) to look up, where n is length of array1 and m is length of array 2

Choose a reason for hiding this comment

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

I would characterize this as O(n + m) where n is the length array1 and m is the length of array2, since you have to loop through each array once.

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.

3 participants