Skip to content

Conversation

@iamsammysam
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. You didn't get to the last method and you have one incomplete method as well. Take a look at my comments and let me know if you have questions. We'll go over them in class.

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

👍

Comment on lines +11 to +12
# Time complexity: O(n^2)
# Space complexity: O(n^2)

Choose a reason for hiding this comment

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

Correct, can you do better than that?

# Space complexity: ?
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def reverse(s)

Choose a reason for hiding this comment

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

👍

raise NotImplementedError, "Method not implemented"
# Time complexity: O(n)
# Space complexity: O(n)
def reverse_inplace(s, first = 0, last = s.length - 1)

Choose a reason for hiding this comment

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

👍

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

Choose a reason for hiding this comment

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

👍

raise NotImplementedError, "Method not implemented"
# Time complexity: O(n)
# Space complexity: O(n)
def nested(s, i = 0)

Choose a reason for hiding this comment

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

  1. This isn't recursive.
  2. It won't work in all cases

end
# Time complexity: O(n)
# Space complexity: O(n)
def search(array, value, index = 0)

Choose a reason for hiding this comment

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

👍

# Space complexity: ?
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def is_palindrome(s)

Choose a reason for hiding this comment

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

👍

Comment on lines 67 to 72
def digit_match(n, m)
raise NotImplementedError, "Method not implemented"
end
return 1 if n == 0 && m == 0
return 0 if n == 0 || m == 0
return 1 if n.to_s[-1] == m.to_s[-1]
end

Choose a reason for hiding this comment

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

You're only checking the last digit here.

Maybe use if n % 10 == m % 10 to compare the last digit and then divide by 10 to repeat with the remaining digits.

def reverse(s)
raise NotImplementedError, "Method not implemented"
return s if s.length <= 1
rev_s = reverse(s[1..-1])

Choose a reason for hiding this comment

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

s[1..-1] creates a new array and copies all the individual elements over and so is O(n) by itself.

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