-
Notifications
You must be signed in to change notification settings - Fork 48
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
Yasmin- Leaves #45
base: master
Are you sure you want to change the base?
Yasmin- Leaves #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
# Space Complexity - ? (should be O(n)) | ||
# Hint, you may want a recursive helper method | ||
def fibonacci(n) | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
# Superdigit | ||
|
||
# Time Complexity - ? | ||
# Space Complexity - ? | ||
# Time Complexity - o(n) | ||
# Space Complexity - o(1) | ||
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The time/space complexity will be O(log10 n) |
||
def super_digit(n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
new_num = 0 | ||
numbers = n.to_s.split("") | ||
if numbers.length <= 1 | ||
return n | ||
end | ||
numbers.each do |i| | ||
new_num += i.to_i | ||
end | ||
return super_digit(new_num) | ||
end | ||
|
||
|
||
# Time Complexity - ? | ||
# Space Complexity - ? | ||
def refined_super_digit(n, k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
new_num = 0 | ||
times = k | ||
numbers = n.to_s.split("") | ||
if numbers.length <= 1 | ||
return n | ||
end | ||
numbers.each do |i| | ||
new_num += i.to_i | ||
end | ||
new_n = times * new_num | ||
return super_digit(new_n) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take another look at the notes on
fibonacci
, there's more than enough there to make a stab at this problem.