-
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
water - marj #45
base: master
Are you sure you want to change the base?
water - marj #45
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.
Nice work Marj, the majority of these work. The only major issue is the time/space complexities. Take a look at my comments and let me know what questions you have.
# Time complexity: n | ||
# Space complexity: 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: n^2 | ||
# Space complexity: n^2 | ||
def reverse(s) #was the answer to this supposed to be different from the one below?? |
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: n | ||
# Space complexity: 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.
👍 This is the same as the previous method and it's not in place.
Consider passing the front and rear indexes and swapping elements at each index.
def reverse_inplace(s, front = 0, last = s.length - 1)
return s if front >= last
temp = s[last]
s[last] = s[front]
s[front] = temp
return reverse_inplace(s, front + 1, last - 1)
end
# Time complexity: n | ||
# Space complexity: 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.
👍 This works.
# Time complexity: n^2 | ||
# Space complexity: n^2 | ||
def nested(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: ? | ||
# Space complexity: ? | ||
def search(array, value) |
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.
This works with O(n^2) space/time complexity.
# Time complexity: n | ||
# Space complexity: 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.
👍 But time/space complexity is O(n^2)
# Time complexity: n | ||
# Space complexity: n | ||
# | ||
# how many calls | ||
# how expensive is each call | ||
def digit_match(n, m) |
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.
👍 This is O(log n) if n is the size of the smaller of the two numbers (basically you divide by 10 each recursive call).
No description provided.