Skip to content

Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 2 | Improve_with_cache#184

Open
TarasMykytiuk wants to merge 2 commits into
CodeYourFuture:mainfrom
TarasMykytiuk:improve_with_caches
Open

Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 2 | Improve_with_cache#184
TarasMykytiuk wants to merge 2 commits into
CodeYourFuture:mainfrom
TarasMykytiuk:improve_with_caches

Conversation

@TarasMykytiuk

@TarasMykytiuk TarasMykytiuk commented Jun 28, 2026

Copy link
Copy Markdown

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

Improve with cache exercise compete.

@TarasMykytiuk TarasMykytiuk added 📅 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. Module-Complexity The name of the module. labels Jun 28, 2026
Comment thread Sprint-2/improve_with_caches/fibonacci/fibonacci.py Outdated
Comment thread Sprint-2/improve_with_caches/making_change/making_change.py Outdated


def ways_to_make_change_helper(total: int, coins: List[int]) -> int:
def ways_to_make_change_helper(total: int, coin_index: 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.

Could also keep the coin list in the parameter so that the function can be reused on different coin list.

When we pass a list to a function, we are only passing its reference -- the cost is negligible.

The cost of evaluating len(list) is also negligible because it merely reads an attribute of the list.

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.

Done.

@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 Jun 28, 2026
@TarasMykytiuk TarasMykytiuk added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jun 28, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All good.



def ways_to_make_change_helper(total: int, coin_index: int) -> int:
def ways_to_make_change_helper(total: int, coin_index: int, coins: List[int], cache = {}) -> 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.

Please note that, unlike JS, default value in Python is only created once on function definition instead of on every function call.

For fibonacci(), the cache is reusable across function calls, so setting the cache as a default parameter is acceptable.

But for ways_to_make_change_helper(), if coins is allowed to contain different coin values, then creating the cache as a default parameter would not be appropriate.

@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. labels Jun 29, 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. 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