Skip to content

Manchester|25-SDC-NOV| Rahwa Haile | Sprint 1|Analyse and refactor#109

Open
RahwaZeslusHaile wants to merge 5 commits intoCodeYourFuture:mainfrom
RahwaZeslusHaile:Analyse-and-Refactor
Open

Manchester|25-SDC-NOV| Rahwa Haile | Sprint 1|Analyse and refactor#109
RahwaZeslusHaile wants to merge 5 commits intoCodeYourFuture:mainfrom
RahwaZeslusHaile:Analyse-and-Refactor

Conversation

@RahwaZeslusHaile
Copy link

@RahwaZeslusHaile RahwaZeslusHaile commented Feb 16, 2026

Manchester|25-SDC-NOV| Rahwa Haile | Sprint 1|Analyse and refactor## 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

This PR includes several improvements and optimizations to utility functions:

  • findCommonItems
    Optimized from O(n × m) to O(n + m) using Set.
    Avoids duplicates and improves performance for large arrays.

  • hasPairWithSum
    Added function to check if any two numbers sum to a target.
    Brute-force version O(n²), later optimized to O(n) with a Set.

  • removeDuplicates
    Refactored from nested loops (O(n²)) to a Set-based solution (O(n) time, O(n) space).
    Preserves original order while removing duplicates.

  • calculateSumAndProduct
    Combined sum and product calculation into a single loop (O(n) time, O(1) space).
    Cleaned up code for readability and efficiency.

All functions are tested and ready to use.

Questions

I would really appreciate your feedback. Thank you for reviewing my submission!

@RahwaZeslusHaile RahwaZeslusHaile added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 16, 2026
Copy link

@SlideGauge SlideGauge left a comment

Choose a reason for hiding this comment

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

Overall, good job in rewriting the algorithms, but could you please update the Time Complexity comment in each function with the initial time complexity? So we can see how time complexity has been improved in Optimal time complexity

Choose a reason for hiding this comment

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

Looks like this file is not needed here

if (numbers[i] + numbers[j] === target) {
return true;
}
const seen = new Set();

Choose a reason for hiding this comment

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

nice use of set

* Time Complexity:
* Space Complexity:
* Optimal Time Complexity:
* Time Complexity: O(n)

Choose a reason for hiding this comment

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

Initial time complexity is worse than O(n)

@SlideGauge SlideGauge 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 1, 2026
@SlideGauge
Copy link

Also, as far as I see you wrote JS only here. Are you going to include python tasks in the same PR or do the separate one?

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