Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work, you hit the learning goals here. Well done. Check my comments below especially with regard to time/space complexity. You also have one broken method, although the tests didnt' catch it. Let me know if you have questions.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def factorial(n) |
| # Space complexity: O(n) | ||
| def reverse_inplace(s, i = 0) | ||
| return s if i == s.length / 2 | ||
| s[i], s[s.length - i - 1] = s[s.length - i - 1], s[i] |
| raise NotImplementedError, "Method not implemented" | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def reverse_inplace(s, i = 0) |
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def bunny(n) |
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n^2) since using .length? |
There was a problem hiding this comment.
.length is actually O(1) because it's an instance variable (for that explicit reason).
| # Space complexity: ? | ||
| # Time complexity: O(n^2) since using .length? | ||
| # Space complexity: O(n) | ||
| def nested(s) |
| return false if array.empty? | ||
| return true if array[0] == value | ||
| new_array = array[1..-1] | ||
| return search(array[1..-1], value) |
There was a problem hiding this comment.
array[1..-1] creates a new array and copies all the individual elements over and so is O(n) by itself.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def search(array, value) |
There was a problem hiding this comment.
👍
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def is_palindrome(s) |
There was a problem hiding this comment.
👍 This works, but you have similar time/space issues with the above methods.
| # Space complexity: ? | ||
| # Time complexity: O(n^2) since it uses .length in each loop? | ||
| # Space complexity: O(n) | ||
| def digit_match(n, m) |
There was a problem hiding this comment.
👍 This works, but you have similar time/space issues with the above methods.
No description provided.