Skip to content

London | 25-SDC-July | Eyuel Abraham | Sprint 2 | Improve with caches #149

Open
eyuell21 wants to merge 4 commits intoCodeYourFuture:mainfrom
eyuell21:improve_with_caches
Open

London | 25-SDC-July | Eyuel Abraham | Sprint 2 | Improve with caches #149
eyuell21 wants to merge 4 commits intoCodeYourFuture:mainfrom
eyuell21:improve_with_caches

Conversation

@eyuell21
Copy link
Copy Markdown

@eyuell21 eyuell21 commented Mar 5, 2026

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

Added memoization to improve performance.

Questions

No Questions.

@eyuell21 eyuell21 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 5, 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 Mar 5, 2026
@github-actions

This comment has been minimized.

@eyuell21 eyuell21 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 6, 2026
@SlideGauge SlideGauge added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Mar 8, 2026
Copy link
Copy Markdown

@SlideGauge SlideGauge left a comment

Choose a reason for hiding this comment

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

Overall decent approaches with solving via caching/memoization. I've got a couple of requests, which will polish both solutions, could you fulfil them?

else:
intermediate = ways_to_make_change_helper(total - total_from_coins, coins=coins[coin_index+1:])
ways += intermediate
ways += ways_to_make_change_helper(remainder, coins[coin_index + 1:], memo)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall good approach with memoization, but I have one tiny request here:
What happens when we do slicing in Python? (i.e. do varOfTypeList[x:y])? Does it allocate additional memory, potentially a lot of? Can we avoid additional allocation of a lot of memory?

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.

In Python, doing list[x:y] creates a new list containing the elements from index x to y-1. This requires allocating additional memory proportional to the slice length. we can use a module called intertools (itertools.islice), which returns a lazy iterator over that range instead of creating a new list to avoid excess memory allocation.

@SlideGauge SlideGauge 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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 8, 2026
@eyuell21
Copy link
Copy Markdown
Author

Hello @SlideGauge, I've made the requested changes.

@eyuell21 eyuell21 requested a review from SlideGauge March 17, 2026 10:23
@eyuell21
Copy link
Copy Markdown
Author

Hello! @illicitonion Can I get a review on this one please? Thank you!

Copy link
Copy Markdown
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Generally looks good - one documentation question



def ways_to_make_change_helper(total: int, coins: List[int]) -> int:
def ways_to_make_change_helper(total: int, coins: List[int], memo: Dict[Tuple[int, int], int]) -> int:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd probably document what the cache key here is in the docstring - it's not obvious what the two values in the tuple are (and it took me a minute to work out why len(coins) was a valid thing to include in the cache key at all).

@illicitonion illicitonion added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 23, 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.

3 participants