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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant