Open
Conversation
CheezItMan
reviewed
Nov 29, 2020
Comment on lines
+3
to
5
| # Time complexity: n | ||
| # Space complexity: n | ||
| def factorial(n) |
Comment on lines
+12
to
+14
| # Time complexity: n^2 | ||
| # Space complexity: n^2 | ||
| def reverse(s) #was the answer to this supposed to be different from the one below?? |
Comment on lines
+22
to
24
| # Time complexity: n | ||
| # Space complexity: n | ||
| def reverse_inplace(s) |
There was a problem hiding this comment.
👍 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
Comment on lines
+55
to
57
| # Time complexity: n | ||
| # Space complexity: n | ||
| def bunny(n) |
Comment on lines
+64
to
66
| # Time complexity: n^2 | ||
| # Space complexity: n^2 | ||
| def nested(s) |
Comment on lines
77
to
79
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| def search(array, value) |
There was a problem hiding this comment.
This works with O(n^2) space/time complexity.
Comment on lines
+88
to
90
| # Time complexity: n | ||
| # Space complexity: n | ||
| def is_palindrome(s) |
There was a problem hiding this comment.
👍 But time/space complexity is O(n^2)
Comment on lines
+99
to
104
| # 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.
👍 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.