Skip to content

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.

# 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

# 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