-
Notifications
You must be signed in to change notification settings - Fork 39
Ports - Ari (in progress!) #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave some notes on what you have so far.
|
|
||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n), where n is the length of the string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically s[0, s.length-1] creates a new string of length n-1, so this solution is actually n^2.
| # Time complexity: O(n), where n is the length of the string | ||
| # Space complexity: O(n), because there will be n layers to the call stack. | ||
| def reverse_inplace(s) | ||
| raise NotImplementedError, "Method not implemented" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not in place.
To do in-place you can create a helper method:
reverse_helper(string, left_index = 0, right_index = string.length -1)
Then each iteration you can swap the characters at left_index and right_index and then call the helper recursively with new values for left_index and right_index. The base case is when left_index == right_index.
|
|
||
| end | ||
|
|
||
| # Time complexity: ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't predict the complexity?
| # Space complexity: ? | ||
| def bunny(n) | ||
| raise NotImplementedError, "Method not implemented" | ||
| if n % 2 == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should actually be:
return 0 if n == 0
return 2 + bunny(n-1)
No description provided.