Skip to content

Conversation

@aribray
Copy link

@aribray aribray commented May 28, 2019

No description provided.

Copy link

@CheezItMan CheezItMan left a 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

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"

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: ?

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

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants