Skip to content

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 1 | analyse refactor functions#99

Open
sheida-shab wants to merge 4 commits intoCodeYourFuture:mainfrom
sheida-shab:Sprint1-analyse-refactor-functions
Open

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 1 | analyse refactor functions#99
sheida-shab wants to merge 4 commits intoCodeYourFuture:mainfrom
sheida-shab:Sprint1-analyse-refactor-functions

Conversation

@sheida-shab
Copy link

  • 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

This PR refactors the following utility functions:

  • calculateSumAndProduct
  • hasPairWithSum
  • removeDuplicates
  • find_common_items

Changes include:

  • Optimizing duplicate removal in removeDuplicates using Set (O(n) instead of O(n²)), preserving the order of first occurrences.
  • Optimizing find_common_items using Python sets and intersection (O(n + m) instead of O(n × m)), which is optimal.
  • Optimizing hasPairWithSum using the two-pointer approach after sorting (O(n log n) instead of O(n²)).
  • General code cleanup in all functions for readability and maintainability.
  • Added explicit documentation of time and space complexity before and after refactoring.

All refactored functions preserve the original behavior and have been tested to ensure correctness.

Time and space complexity have been improved where applicable:

  • removeDuplicates: Time O(n), Space O(n), Optimal O(n)
  • find_common_items: Time O(n + m), Space O(n + m), Optimal O(n + m)
  • hasPairWithSum: Time O(n log n), Space O(1), Optimal O(n)
  • calculateSumAndProduct: Time O(n), Space O(1), Optimal O(n)

References:

@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Complexity The name of the module. 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