Skip to content

London | 26-SDC-Mar | beko | Sprint 2 | improve code with caches#190

Open
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-improve-code-with-caches
Open

London | 26-SDC-Mar | beko | Sprint 2 | improve code with caches#190
Abubakar-Meigag wants to merge 1 commit into
CodeYourFuture:mainfrom
Abubakar-Meigag:beko-improve-code-with-caches

Conversation

@Abubakar-Meigag

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

Completed improve code with caches

@Abubakar-Meigag Abubakar-Meigag 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 30, 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.

Looks good.

Comment on lines +2 to 4
cache = {}

def fibonacci(n):

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 you look into an approach that doesn't require keeping the cache in the global scope?

Change is optional.

Comment on lines +11 to +17
coins = [200, 100, 50, 20, 10, 5, 2, 1]
ways = [0] * (total + 1)
ways[0] = 1

for coin in coins:
for amount in range(coin, total + 1):
ways[amount] += ways[amount - coin]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This iterative approach is quicker but it would beat the purpose of using cache to improve an existing recursive solution.



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

Even though you didn't use this helper function, you correctly implemented it to use a cache to improve the original implementation.

@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 30, 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