Skip to content

Conversation

@Droid-An
Copy link

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

Improved code by adding cache caches

Questions

no questions

@Droid-An Droid-An added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 13, 2025
@OracPrime OracPrime added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jan 26, 2026
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

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

Fibonacci is fine, but coins needs a little more thought

if n not in cache:
cache[n] = fibonacci(n - 1) + fibonacci(n - 2)
return cache[n]
else:

Choose a reason for hiding this comment

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

It's personal taste as to which way you do it, but the code would be more concise without lines 9 and 10, and with 11 outside the if.

else:
intermediate = ways_to_make_change_helper(total - total_from_coins, coins=coins[coin_index+1:])
key = (total - total_from_coins, tuple(coins[coin_index + 1 :]))
if key not in cache:

Choose a reason for hiding this comment

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

converting the list to a tuple every time is going to be expensive. Also at each stage you're creating a new list, which will also be expensive. The new lists are always the same list, but starting later. Can you think of a way you could refactor the code so that it always uses the same tuple, and the recursion is achieved by passing a parameter indicating where the first usable entry in the tuple is? In that situation, how much can you simplify the key to the cache as well?

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants