Skip to content

Conversation

@Kimberly-Fasbender
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.

Really nice work, you hit all the learning goals here. Take a look at my comments regarding time complexity and let me know if you have questions.


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) - where n is equal to the length of the input string

Choose a reason for hiding this comment

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

Because s[0..-2] will also create a new array, this makes the time complexity also O(n^2)

raise NotImplementedError, "Method not implemented"
# Time complexity: O(n) - where n is the length of the string / 2
# Space complexity: O(n) - where n is the length of the string / 2
def reverse_inplace(s, i = 0, j = s.length - 1)

Choose a reason for hiding this comment

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

👍 Outstanding!

raise NotImplementedError, "Method not implemented"
if s == ""
return true
elsif s.length == 1 || s[0] != "(" || s[-1] != ")"

Choose a reason for hiding this comment

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

if s.length ==1 then it can't have a matching paren.


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) - where n equal the length of the string / 2

Choose a reason for hiding this comment

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

Because s[1..-2] creates a new string of length n-2, this is an O(n^2) for both space and time.


# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) - where n equals the length of the array

Choose a reason for hiding this comment

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

Similar to the above O(n^2)

# Space complexity: ?
# Time complexity: O(n) - where n equals the length of the string / 2
# Space complexity: O(n) - where n equals the length of the string / 2 + length of the string
def is_palindrome(s)

Choose a reason for hiding this comment

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

O(n^2) similar to the above, look at your reverse in place, could you use a similar technique?

def digit_match(n, m)
raise NotImplementedError, "Method not implemented"
end No newline at end of file
if (n / 10 == 0) || (m / 10 == 0)

Choose a reason for hiding this comment

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

These ifs could be simplified a bit. Otherwise very good!

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