Skip to content

Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | Improve Code with Caches - #254

Open
shreefAhmedM wants to merge 2 commits into
CodeYourFuture:mainfrom
shreefAhmedM:mprove_with_caches
Open

shreefAhmedM wants to merge 2 commits into
CodeYourFuture:mainfrom
shreefAhmedM:mprove_with_caches

Conversation

@shreefAhmedM

@shreefAhmedM shreefAhmedM commented Oct 14, 2026 •

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

Task code

CYF-1182

Changelist

I struggled a bit with these two tasks

@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@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 14, 2026
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 |improve_with_precomputing Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | improve_with_precomputing Oct 14, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@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 14, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | improve_with_precomputing Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing CYF-1183 Oct 14, 2026
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing CYF-1183 Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing Oct 14, 2026
@github-actions

This comment has been minimized.

@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 2026
@github-actions

This comment has been minimized.

@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 14, 2026
@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-JUL-SDC |Shreef Ibrahim | Sprint 2 |Improve precomputing Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | Improve Code with Caches Oct 16, 2026
@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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

This comment has been minimized.

@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
@shreefAhmedM shreefAhmedM changed the title Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint-2 | Improve Code with Caches Glasgow | 26-Jul-SDC | Shreef Ibrahim | Sprint 2 | Improve Code with Caches Oct 16, 2026
@shreefAhmedM shreefAhmedM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
Comment on lines +8 to +26
def helper(remaining: int, coin_index: int) -> int:
if remaining == 0:
return 1

if remaining < 0 or coin_index == len(coins):
return 0

key = (remaining, coin_index)

if key in cache:
return cache[key]

result = (
helper(remaining - coins[coin_index], coin_index)
+ helper(remaining, coin_index + 1)
)

cache[key] = result
return result

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 code is basically rewritten. Could you describe how this implementation is more efficient than the original implementation?

Comment on lines +28 to +29
if total < 0:
return 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could also just let helper handle this case.

return helper(total, 0)


def ways_to_make_change_helper(total: int, coins: List[int]) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Where is ways_to_make_change_helper being used?

@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 Oct 16, 2026
@shreefAhmedM shreefAhmedM added 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

Looks good.

Note: Changelist should be about what was changed.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 16, 2026
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants