Skip to content

NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | improve with caches#177

Open
ZabihollahNamazi wants to merge 2 commits into
CodeYourFuture:mainfrom
ZabihollahNamazi:s2-improve-with-cache
Open

NW | 26-SDC-Mar | Zabihollah Namazi | Sprint 2 | improve with caches#177
ZabihollahNamazi wants to merge 2 commits into
CodeYourFuture:mainfrom
ZabihollahNamazi:s2-improve-with-cache

Conversation

@ZabihollahNamazi

@ZabihollahNamazi ZabihollahNamazi commented Jun 24, 2026

Copy link
Copy Markdown
  • 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

Hi! Could you please check my code?

I changed the Fibonacci and Making Change code. The old code was too slow and crashed with big numbers. I fixed it by using caching and loops so the code runs fast and passes all the big tests instantly.

Thank you!

@ZabihollahNamazi ZabihollahNamazi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module labels Jun 24, 2026
Comment on lines +8 to +17
prev2 = 0 # fibonacci(0)
prev1 = 1 # fibonacci(1)

# Calculate upward to n
for _ in range(2, n + 1):
current = prev1 + prev2
prev2 = prev1
prev1 = current

return prev1 No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replacing the recursive approach with an iterative one defeats the purpose of this exercise, which is to improve the performance of a recursive function using caching. Could you update the code while keeping the original recursive implementation?

Comment on lines +2 to +12
coins = [1, 2, 5, 10, 20, 50, 100, 200]

dp = [0] * (total + 1)

dp[0] = 1

for coin in coins:
for i in range(coin, total + 1):
dp[i] += dp[i - coin]

return dp[total] No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job in finding out a faster approach to find the solution.

Could you also include an implementation that uses cache to speed up the original recursive implementation?

@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 26, 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. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants