Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work, I left some notes, but you did a good job writing the methods. You do need to know that creating a string does add some time and space complexity to solutions.
Let me know if you have questions.
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: o(n) where n is the length of the string |
There was a problem hiding this comment.
Since s[0...s.length-1] creates a new string, this algorithm is actually O(n^2)
| def reverse_inplace(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| return s if s == "" | ||
| return s[-1] + reverse_inplace(s[0...-1]) |
There was a problem hiding this comment.
This is creating new strings, so it isn't in place.
To do it in place you need to swap characters one at a time without creating a new string.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(1) (or O(n) cause it has that count to create and return?) |
There was a problem hiding this comment.
Since you have a system stack, it's O(n)
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) (well, O(n/2)) |
There was a problem hiding this comment.
Due to creating a new string it's actually O(n^2)
| raise NotImplementedError, "Method not implemented" | ||
| if array.length == 0 | ||
| return false | ||
| elsif array.length >= 1 && array[0] == value |
There was a problem hiding this comment.
You don't need the array.length >= 1
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) |
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) |
| # Space complexity: O(1) | ||
| def is_palindrome(s) | ||
| raise NotImplementedError, "Method not implemented" | ||
| if (s.length == 3 && s[0] == s[-1]) || (s.length == 2 && s[0] == s[-1]) || s.length == 0 |
There was a problem hiding this comment.
This could probably be simplified to return true if s.length <= 1
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) | ||
| # Space complexity: O(1) |
There was a problem hiding this comment.
Space complexity is O(n) due to the system stack space.
No description provided.