Skip to content

Conversation

@Luke-Manyamazi
Copy link

@Luke-Manyamazi Luke-Manyamazi commented Nov 10, 2025

Learners, PR Template

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

Changelist

  • calculateSumAndProduct (JS): Optimized from two sequential O(N) loops to a single O(N) loop, reducing array traversals by 50%.
  • findCommonItems (JS): Reduced time complexity from O(N * M) to O(N + M) by using a Set for O(1) average-time lookups.
  • has_pair_with_sum (Python): Reduced time complexity from O(N^2) to O(N) by using a hash set to track complements.
  • remove_duplicates (Python): Reduced time complexity from O(N^2) to O(N) by using a hash set to track seen items while preserving order.

Questions

  1. Readability vs. Conciseness (JS findCommonItems): I provided both a detailed, multi-line refactor and a concise one-line version for findCommonItems using the Set object. Which style is preferred for functions of this nature in our codebase?

@Luke-Manyamazi Luke-Manyamazi 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 Nov 10, 2025
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.

Your analysis looks good.

Comment on lines +23 to 28
// The complexity is reduced by combining the two sequential O(N) loops
// into a single O(N) loop, cutting the number of array traversals in half.
for (const num of numbers) {
sum += num;
product *= num;
}
Copy link

Choose a reason for hiding this comment

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

Performance can be improved by combining the loops, but the complexity remains O(N).

In complexity analysis, the constant factor is ignored.
N, 2N, or even 100N operations, are all considered as O(N) complexity.

Time Complexity:
Space Complexity:
Optimal time complexity:
Time Complexity: O(N)
Copy link

Choose a reason for hiding this comment

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

I think this "Time Complexity" refers to the complexity of the original code, and the optimal one refers to the refactored code.

@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 Jan 25, 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. 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