Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
You didn't quite finish them all and you didn't manage to do reverse in place. However the other methods are pretty well done although several lack space/time complexity. Take a look at my comments and let me know what questions you have.
| # Time complexity: O(n) ['n' being the number of times factorial computation has to be implemented until n reaches 0] | ||
| # Space complexity: 0(n) ['n' being the number of function calls on the stack] | ||
| def factorial(n) |
| # Time complexity: O(n^2) | ||
| # Space complexity: O(n^2) | ||
| def reverse(s, i = 1) |
lib/recursive-methods.rb
Outdated
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| def reverse_inplace(s) |
There was a problem hiding this comment.
| # Time complexity: ? | |
| # Space complexity: ? | |
| def reverse_inplace(s) | |
| # Time complexity: ? | |
| # Space complexity: ? | |
| def reverse_inplace(s, low = 0, high = s.length - 1) |
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def bunny(n) |
lib/recursive-methods.rb
Outdated
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| def nested(s) |
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| def search(array, value) | ||
| raise NotImplementedError, "Method not implemented" | ||
| def search(array, value, i = 0) |
lib/recursive-methods.rb
Outdated
| def digit_match(n, m) | ||
| raise NotImplementedError, "Method not implemented" | ||
| end No newline at end of file | ||
| puts "Sorry, I couldn't figure this one out!" |
There was a problem hiding this comment.
Understood, does this help?
| puts "Sorry, I couldn't figure this one out!" | |
| if n == 0 || m == 0 | |
| return n % 10 == m % 10 ? 1 : 0 | |
| end | |
| new_n = n / 10 | |
| new_m = m / 10 | |
| if n % 10 == m % 10 | |
| # your code |
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Kayla, thanks for getting this in. This is outstanding work. Take a look at my comments and let me know what questions you have.
| # Time complexity: O(n) -still has to iterate over every element in string | ||
| # Space complexity: O(n) -stack can get very large if string is big | ||
| def reverse_inplace_helper(s, start, finish) |
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def digit_helper(n, m, match = 0, place = 0) |
| # Time complexity: O(n) best case O(1) if item is in index 1? | ||
| # Space complexity: O(n) best case O(1) if item is in index 1? | ||
| def search(array, value, i = 0) |
| # Time complexity: O(n) | ||
| # Space complexity: O(n) | ||
| def nested(s) |
There was a problem hiding this comment.
Due to the slice you're doing, this is O(n^2) for both time/space.
Otherwise 👍
| # Time complexity: O(n) - traversing the whole string | ||
| # Space complexity: O(n) -traversing the whole string | ||
| def is_palindrome(s) |
There was a problem hiding this comment.
Due to the slice this is O(n^2), but otherwise 👍
No description provided.