Skip to content

London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 1 | Analyse and refactor functions#141

Open
aydaeslami wants to merge 10 commits intoCodeYourFuture:mainfrom
aydaeslami:Analyse-and-Refactor-Functions
Open

London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 1 | Analyse and refactor functions#141
aydaeslami wants to merge 10 commits intoCodeYourFuture:mainfrom
aydaeslami:Analyse-and-Refactor-Functions

Conversation

@aydaeslami
Copy link

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • [x]My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Refactored functions to reduce time complexity by removing nested loops and using sets for faster lookups, improving overall performance.

@aydaeslami aydaeslami added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 1, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

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.

Copy link

Choose a reason for hiding this comment

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

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)

Comment on lines +20 to +21
if i in second_sequence_set and i not in common_items:
common_items.append(i)
Copy link

Choose a reason for hiding this comment

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

Can also consider using a built-in set operation for better performance and simpler code.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your feedback @cjyuan !I’ve made the suggested changes, including using the built-in set intersection and updating the complexity comments. Please let me know if anything else needs improvement.

Copy link

Choose a reason for hiding this comment

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

The new implementation looks good.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 2, 2026
@aydaeslami aydaeslami added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 17, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Can you also show the time complexity of the original implementation (in each file)?

Time Complexity:
Space Complexity:
Optimal time complexity:
Time Complexity: O(n + m) process both sequences
Copy link

Choose a reason for hiding this comment

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

The complexity of the original implementation is not O(n+m).

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants