Skip to content

London | 26-JUL-SDC |Ping Wang | Sprint 1 | Analyze and Refactor CYF-1173 - #229

Open
pathywang wants to merge 2 commits into
CodeYourFuture:mainfrom
pathywang:sprint-1
Open

pathywang wants to merge 2 commits into
CodeYourFuture:mainfrom
pathywang:sprint-1

Conversation

@pathywang

Copy link
Copy Markdown

Self checklist

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

Task code

CYF-1173

Changelist

did prep and get general idea about JavaScript and Python. Also learn from test and give explanation about refactor.

@github-actions

This comment has been minimized.

@pathywang pathywang changed the title London | 26-JUL-SDC |Ping Wang | spint 1 | Analyze and Refactor CYF-1173 London | 26-JUL-SDC |Ping Wang | Spint 1 | Analyze and Refactor CYF-1173 Oct 4, 2026
@github-actions

This comment has been minimized.

@pathywang pathywang changed the title London | 26-JUL-SDC |Ping Wang | Spint 1 | Analyze and Refactor CYF-1173 London | 26-JUL-SDC |Ping Wang | Sprint 1 | Analyze and Refactor CYF-1173 Oct 4, 2026
@pathywang pathywang added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 4, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The complexity analysis on the JS implementation looks good.

Comment on lines 12 to 22

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The complexity of this Python implementation is not O(nm).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, time complexity will be O(nnm) so i change the code with AI help which is a bit hard for me to understand. So Time complexity: O(n+m), am i right?

Copy link
Copy Markdown

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 more like O( nm * min(m, n) ), or loosely $O(n^3)$ if we assume both lists are about the same size.

Yes, your refactored implementation is $O(n + m)$.

Comment on lines +36 to +41
// For two loops, we have visit each element of array in order to get the result
// so time complexity is O (n) which means linear.
// Regarding space complexity, we only get one result
// for sum and product no matter how long the array is.so it is O(1)(constant)
// While time complexity is O(n), optimal time complexity should be O(n) because loop
// has to go each single element in array.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: While the complexity remains $O(1)$, combining the loops into one could often slightly improve the performance.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, i put one loop now which make a bit faster with updated comment

@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 Oct 8, 2026
@pathywang pathywang added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 9, 2026
@cjyuan

cjyuan commented Oct 9, 2026

Copy link
Copy Markdown

All good. Well done.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 9, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants