London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 1 | Analyse and refactor functions#141
Open
aydaeslami wants to merge 8 commits intoCodeYourFuture:mainfrom
Open
London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 1 | Analyse and refactor functions#141aydaeslami wants to merge 8 commits intoCodeYourFuture:mainfrom
aydaeslami wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
reviewed
Mar 2, 2026
cjyuan
left a comment
There was a problem hiding this comment.
Code is good.
Can you also show the time complexity of the original implementation?
Comment on lines
4
to
+7
| * Time Complexity: | ||
| * Space Complexity: | ||
| * ANSWER: O(n + m) | ||
| Because the second array is converted into a Set once, and the first array is looped through once. | ||
|
|
There was a problem hiding this comment.
I think "Time Complexity" here refers to the time complexity of the original implementation, and "Optimal Time Complexity" refers to the time complexity of the refactored version. (Otherwise they will always have the same complexity)
| export const findCommonItems = (firstArray, secondArray) => { | ||
| const secondSet = new Set(secondArray); | ||
|
|
||
| return [...new Set(firstArray.filter(item => secondSet.has(item)))]; |
There was a problem hiding this comment.
Note: Set object has a built-in method that can be used to find the "common items" between two sets.
Using built-in method usually means better performance and shorter code.
Comment on lines
+20
to
+21
| if i in second_sequence_set and i not in common_items: | ||
| common_items.append(i) |
There was a problem hiding this comment.
Can also consider using a built-in set operation for better performance and simpler code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Self checklist
Changelist
Refactored functions to reduce time complexity by removing nested loops and using sets for faster lookups, improving overall performance.