Skip to content

BARCELONA | CLASS-OCT2025-2 | CARLOS MARQUINA | SPRINT 1 | [TASK] Analyse and Refactor Functions - #222

Closed
marquinacarlos wants to merge 4 commits into
CodeYourFuture:mainfrom
marquinacarlos:feat/refactor-complexity-functions
Closed

BARCELONA | CLASS-OCT2025-2 | CARLOS MARQUINA | SPRINT 1 | [TASK] Analyse and Refactor Functions#222
marquinacarlos wants to merge 4 commits into
CodeYourFuture:mainfrom
marquinacarlos:feat/refactor-complexity-functions

Conversation

@marquinacarlos

Copy link
Copy Markdown

Task: Analyse and Refactor Functions

Identified inefficiencies in four provided functions (JavaScript and Python) and refactored them to reduce time complexity using Set-based lookups.

Changes

  • calculateSumAndProduct (JS + Python): Combined two separate loops into a single loop. Complexity stays O(n) but removes redundant iteration.
  • removeDuplicates (JS + Python): Replaced O(n^2) inner loop with a Set for O(1) duplicate checks, reducing to O(n).
  • hasPairWithSum (JS + Python): Replaced O(n^2) nested loops with a Set-based complement lookup, reducing to O(n).
  • findCommonItems (JS + Python): Converted second array to a Set for O(1) membership checks, reducing from O(n*m) to O(n+m).

All functions include Big O annotations for original complexity, space complexity, and optimal complexity.

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

@github-actions

Copy link
Copy Markdown

Your PR's title didn't contain a known region.

Please check the expected title format, and make sure your region is in the correct place and spelled correctly.

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant