Skip to content

Comments

West Midlands | 25-SDC-July | Gabriel Deng | Sprint 1 | Analyse and refactor functions#69

Open
gai93003 wants to merge 8 commits intoCodeYourFuture:mainfrom
gai93003:Analyse_and_refactor_functions
Open

West Midlands | 25-SDC-July | Gabriel Deng | Sprint 1 | Analyse and refactor functions#69
gai93003 wants to merge 8 commits intoCodeYourFuture:mainfrom
gai93003:Analyse_and_refactor_functions

Conversation

@gai93003
Copy link

Learners, PR Template

@gai93003 gai93003 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. Module-Complexity The name of the module. labels Jan 11, 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.

  • I could not find the complexity analysis of the original and the refactored code.

  • The PR description does not have much info about this PR.

@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 Jan 23, 2026
@gai93003
Copy link
Author

gai93003 commented Feb 14, 2026

Thanks @cjyuan for the review. I have added the analysis as comments on the individual exercises

Comment on lines +18 to +20

// In this case, the time complexity is O(n * m), it will only become O(n^2) when the two arrays have equal lengths. This case easily be avoided by using a set to store the second sequence. When checking for a match in the set using item in second-set, this has a time complexity of O(1).

Copy link

Choose a reason for hiding this comment

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

What is the complexity of the improved approach?

Copy link
Author

Choose a reason for hiding this comment

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

The complexity for this improved approach is O(n + m) compared to the original O(n * m)

Comment on lines 4 to 7
* Time Complexity: O(n)
* Space Complexity: O(n)
* Optimal Time Complexity: O(1)
*
Copy link

Choose a reason for hiding this comment

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

Are these the complexities of the original function, the improved function, or something else?

An O(1) approach? How?

Copy link
Author

@gai93003 gai93003 Feb 21, 2026

Choose a reason for hiding this comment

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

I mixed the complexities around and they are for this improved function,

Time complexity is O(n) as you have to scan through the whole array
Space complexity is O(1) because it is constant extra memory
Optimal Time Complexity could be O(n) with the use of a set

@cjyuan
Copy link

cjyuan commented Feb 21, 2026

Changes look good.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 21, 2026
@gai93003
Copy link
Author

Thank you for the review @cjyuan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants