Skip to content

Conversation

@lebaongoc
Copy link

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.

Not bad, see my inline notes. You did miss the cost of some built-in Ruby methods, but overall very well done. I like your reverse in place!

@@ -0,0 +1,16 @@
def square_of_two(n)

Choose a reason for hiding this comment

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

huh?

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

Choose a reason for hiding this comment

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

👍


# 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.

This is actually O(n^2) because s[0..s.length - 2] creates an entirely new string of length n-1.


# Time complexity: O(n)
# Space complexity: O(1)
def reverse!(s, b, e)

Choose a reason for hiding this comment

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

Great work! 👍

end

# 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.


# 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.

This one is O(n^2) for the same reasons as reverse, for both space & time


# 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), think about how you solved reverse in place, could you use that technique to make this more efficient?

return s[0] == s[s.length - 1] && is_palindrome(s[1..s.length - 2])
end

# Time complexity: ?

Choose a reason for hiding this comment

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

O(n) for both space and time

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