Skip to content

London | 26-SDC-March | Jamal Laqdiem| Sprint 2 | Improve code with caches - #214

Open
jamallaqdiem wants to merge 4 commits into
CodeYourFuture:mainfrom
jamallaqdiem:improve_with_cahes
Open

jamallaqdiem wants to merge 4 commits into
CodeYourFuture:mainfrom
jamallaqdiem:improve_with_cahes

Conversation

@jamallaqdiem

Copy link
Copy Markdown

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

Optimised both exercises using local function caches and index-based tracking to eliminate global scope variables and slow array allocations

@jamallaqdiem jamallaqdiem added Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 13, 2026
Comment on lines +36 to +37
ways_to_make_change_helper(total - current_coin, coins, coin_index) +
ways_to_make_change_helper(total, coins, coin_index + 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The original "loop" version and your "without loop" version differ in terms of how deep the recursion can go, which affects the amount of stack space required at runtime. For a large total, the program may exceed the available stack space and fail.

Could you update your code to match the original approach as much as possible?

Notes:

  • Supposedly, one level of loop is enough.
  • When there is only one coin left to consider, there is a much quicker way to figure out if there is 0 or 1 way to make the change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@cjyuan thanks for the review, I've updated the code to use a single loop for the current coin and added a quick shortcut check when only one coin is left to prevent deep recursion.

@cjyuan cjyuan 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 Jul 14, 2026
@jamallaqdiem jamallaqdiem added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@github-actions

Copy link
Copy Markdown

Your PR didn't include a Task ID in its description.

Make sure you have put the correct Task ID in its description.

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.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@cjyuan

cjyuan commented Oct 16, 2026

Copy link
Copy Markdown

Changes look good.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown

Your PR didn't include a Task ID in its description.

Make sure you have put the correct Task ID in its description.

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.

1 similar comment
@github-actions

Copy link
Copy Markdown

Your PR didn't include a Task ID in its description.

Make sure you have put the correct Task ID in its description.

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

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants