Skip to content

London | 26-SDC-Mar | Ebrahim Beiati-Asl | Sprint 2 | improve_with_caches#156

Open
ebrahimbeiati wants to merge 1 commit into
CodeYourFuture:mainfrom
ebrahimbeiati:improve_with_caches_pr
Open

London | 26-SDC-Mar | Ebrahim Beiati-Asl | Sprint 2 | improve_with_caches#156
ebrahimbeiati wants to merge 1 commit into
CodeYourFuture:mainfrom
ebrahimbeiati:improve_with_caches_pr

Conversation

@ebrahimbeiati
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

@ebrahimbeiati ebrahimbeiati added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 16, 2026
Copy link
Copy Markdown

@cjyuan cjyuan left a comment

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 +1 to +10
def fibonacci(n, cache=None):
if cache is None:
cache = {}
if n in cache:
return cache[n]
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
else:
cache[n] = fibonacci(n - 1, cache) + fibonacci(n - 2, cache)
return cache[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 also consider using inner function:

def fibonacci(n):
    cache = {}          # Accessible in fib_helper()
    def fib_helper(n):
       ... 

    return fib_helper(n);

or just declare cache in the global scope since the values in the cache are still valid in subsequent call to fibonacci(n).

Comment on lines +23 to 25
if total < 0 or coin_index == len(coins):
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.

Note: When coin_index == len(coins) - 1, there is a quicker way to determine if the number of ways is 0 or 1 without involving cache lookup.

@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 May 17, 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