-
Notifications
You must be signed in to change notification settings - Fork 53
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
Fire - Noor #37
base: master
Are you sure you want to change the base?
Fire - Noor #37
Conversation
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.
Some issues here, and other methods are well done. Take a look at my comments and let me know what questions you have via Slack.
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def factorial(n) |
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.
👍
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def reverse(s) |
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.
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def reverse_inplace(s) |
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.
Think about if we changed the method signature to the following
# Time complexity: O(n) | |
# Space complexity: O(n) | |
def reverse_inplace(s) | |
# Time complexity: O(n) | |
# Space complexity: O(n) | |
def reverse_inplace(s, low = 0, high= s.length - 1) |
Can you see a way to do this with O(n) space/time complexity now?
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def bunny(n) |
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.
👍
if s[i+1] == "(" && s[-i] == ")" | ||
return true |
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.
if s[i+1] == "(" && s[-i] == ")" | |
return true | |
if s[i-1] == "(" && s[-i] == ")" | |
return nested(s, i + 1) |
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def search(array, value, i = 0) |
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.
👍
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def is_palindrome(s) |
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.
👍 Because of the slice you are doing with each recursive call, it's O(n^2)
if n[i] == m[i] | ||
return count + 1 | ||
else | ||
return count | ||
end | ||
|
||
return digit_match(n, m, i + 1, count) |
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.
if n[i] == m[i] | |
return count + 1 | |
else | |
return count | |
end | |
return digit_match(n, m, i + 1, count) | |
if n[i] == m[i] | |
count += 1 | |
end | |
return digit_match(n, m, i + 1, count) |
n.to_s | ||
m.to_s |
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.
n.to_s | |
m.to_s | |
n = n.to_s | |
m = m.to_s |
# Time complexity: O(n) | ||
# Space complexity: O(n) | ||
def digit_match(n, m, i = 0, count = 0) |
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.
No description provided.