Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniela - Leaves #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Daniela - Leaves #27

wants to merge 5 commits into from

Conversation

dnsanche
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Overall nice work, take a look at my comments and let me know if you have any questions.

@@ -1,8 +1,20 @@
# Improved Fibonacci

# Time Complexity - ?
# Time Complexity - O(n)
# Space Complexity - ? (should be O(n))
# Hint, you may want a recursive helper method
def fibonacci(n)

Choose a reason for hiding this comment

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

This works, but you don't need to keep the entire list of fibonacci numbers for the entire length of the recursion. Instead you only need to keep the last two fibonacci numbers.

def super_digit(n)


return n if [0,1,2,3,4,5,6,7,8,9].include?(n) == true

Choose a reason for hiding this comment

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

Why not just:

Suggested change
return n if [0,1,2,3,4,5,6,7,8,9].include?(n) == true
return n if n < 10

# Time Complexity - ?
# Space Complexity - ?
# Time Complexity - O(n), depends on number of digits
# Space Complexity : O(1) as the array of digits will always be same and I will always have same variables (sum, reminder, superdigit)
def refined_super_digit(n, k)

Choose a reason for hiding this comment

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

This works, but you can use the super_digit method previously to help solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants