Skip to content

Conversation

@kaseea
Copy link

@kaseea kaseea commented May 27, 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.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have a system stack, it's O(n)


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) (well, O(n/2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the array.length >= 1


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(n^2)


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(n^2)

# 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be simplified to return true if s.length <= 1

# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space complexity is O(n) due to the system stack space.

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