Skip to content

London | 26-SDC-Mar | Craig D'Silva| Sprint 2 | Improve code with caches#192

Open
craig-dsilva wants to merge 3 commits into
CodeYourFuture:mainfrom
craig-dsilva:caches
Open

London | 26-SDC-Mar | Craig D'Silva| Sprint 2 | Improve code with caches#192
craig-dsilva wants to merge 3 commits into
CodeYourFuture:mainfrom
craig-dsilva:caches

Conversation

@craig-dsilva

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

Changelist

Improve code with caches

@craig-dsilva craig-dsilva added 🏕 Priority Mandatory This work is expected 🐂 Size Medium 1-4 hours 📅 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
Comment on lines +4 to +8
nums = [0, 1]
i = 0
while i < n:
nums.append(nums[len(nums) - 1] + nums[len(nums) - 2])
i += 1

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 would beat the purpose of the exercise -- to use cache to improve the original recursive function.

Could you update your code to use a cache to improve the original implementation?

Comment on lines +17 to +22
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.

Could you also replace this iterative version?

@cjyuan cjyuan 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. labels Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Complexity The name of the module. 🏕 Priority Mandatory This work is expected Reviewed Volunteer to add when completing a review with trainee action still to take. 🐂 Size Medium 1-4 hours 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants