Skip to content

Conversation

@Faiza1987
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.

This is a solid brute-force solution. However you could get it down to an O(n + m) time complexity using a hash. I encourage you to give it a try.

# Returns a new array to that contains elements in the intersection of the two input arrays
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n^2) because there are nested loops and n is the length of the input array

Choose a reason for hiding this comment

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

The two arrays are not guaranteed to be of the same length. This is more accurate to be O(n + m) where n and m are the lengths of the respective arrays.

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