Skip to content

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

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

pathywang wants to merge 1 commit 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
Time Complexity:O(nm)
Space Complexity:O(n+m)
Optimal time complexity:O(n+m)
which is the same as JavaScript const findCommonItems = (firstArray, secondArray)
"""
common_items: List[ItemType] = []
for i in first_sequence:
for j in second_sequence:
if i == j and i not in common_items:
common_items.append(i)
return common_items

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).

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants