Skip to content

Conversation

@PratiAmalden
Copy link

@PratiAmalden PratiAmalden commented Dec 12, 2025

No description provided.

@github-actions
Copy link

Your PR description contained template fields which weren't filled in.

Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed.

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@PratiAmalden PratiAmalden added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
@github-actions
Copy link

Your PR description contained template fields which weren't filled in.

Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed.

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
@PratiAmalden PratiAmalden added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 12, 2025
Comment on lines +32 to +40
count_of_coin = 0

while coin * count_of_coin <= total:
total_from_coins = coin * count_of_coin
intermediate = ways_to_make_change_helper(total - total_from_coins, rest)
ways += intermediate
count_of_coin += 1

_change_cache[key] = ways
Copy link

Choose a reason for hiding this comment

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

Great job in identifying that we could get rid of the outer for loop.

Comment on lines +24 to +29
key = (total, coins)
if key in _change_cache:
return _change_cache[key]

coin = coins[0]
rest = coins[1:]
Copy link

Choose a reason for hiding this comment

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

From line 29, we could identify coins can only be one of the following 9 tuples:

(200, 100, 50, 20, 10, 5, 2, 1)
(100, 50, 20, 10, 5, 2, 1)
(50, 20, 10, 5, 2, 1)
...
(1)
()

We could further improve the performance if we can

  • avoid repeatedly creating the same sub-tuples at line 29 (e.g. use another cache), and
  • create key as (total, an_integer_that_map_to_the_subtuple) instead of as (total, tuple of coins)

I don't think this exercise expects trainees to optimize the code to this level. So change is optional.

@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 Jan 25, 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