Conversation
CheezItMan
reviewed
Nov 14, 2019
CheezItMan
left a comment
There was a problem hiding this comment.
Not bad. You didn't get to the last method and you have one incomplete method as well. Take a look at my comments and let me know if you have questions. We'll go over them in class.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def factorial(n) |
Comment on lines
+11
to
+12
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) |
There was a problem hiding this comment.
Correct, can you do better than that?
| # Space complexity: ? | ||
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) | ||
| def reverse(s) |
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def reverse_inplace(s, first = 0, last = s.length - 1) |
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def bunny(n) |
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def nested(s, i = 0) |
There was a problem hiding this comment.
- This isn't recursive.
- It won't work in all cases
| end | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def search(array, value, index = 0) |
| # Space complexity: ? | ||
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) | ||
| def is_palindrome(s) |
Comment on lines
67
to
72
| def digit_match(n, m) | ||
| raise NotImplementedError, "Method not implemented" | ||
| end No newline at end of file | ||
| return 1 if n == 0 && m == 0 | ||
| return 0 if n == 0 || m == 0 | ||
| return 1 if n.to_s[-1] == m.to_s[-1] | ||
| end |
There was a problem hiding this comment.
You're only checking the last digit here.
Maybe use if n % 10 == m % 10 to compare the last digit and then divide by 10 to repeat with the remaining digits.
| def reverse(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| return s if s.length <= 1 | ||
| rev_s = reverse(s[1..-1]) |
There was a problem hiding this comment.
s[1..-1] creates a new array and copies all the individual elements over and so is O(n) by itself.
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.