Skip to content

Conversation

@kristyh32
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.

Overall nice work, you hit the learning goals here. Well done. Check my comments below especially with regard to time/space complexity. Also a small bug in digit_match. Let me know if you have questions.

@@ -0,0 +1,46 @@
def binary_search(array, to_find)

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.

👍

def reverse(s)
raise NotImplementedError, "Method not implemented"
return s if s.length == 1 || s.empty?
return s[-1] + reverse(s[1..-2]) + s[0]

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.

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

Choose a reason for hiding this comment

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

👍
This works, but because you create a new array with each recursive call this is O(n2) for both time/space complexity.

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

👍

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
def nested(s)

Choose a reason for hiding this comment

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

👍 This works, but you have similar time/space issues with the above methods.

# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(n)
def search(array, value)

Choose a reason for hiding this comment

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

👍 This works, but you have similar time/space issues with the above methods.

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

Choose a reason for hiding this comment

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

👍 This works, but you have similar time/space issues with the above methods.

Comment on lines +64 to +68
return 1 if n == 0 && m == 0
return 0 if n == 0 || m == 0
return 1 if n.digits[0] == 0 && m.digits[0] == 0
return 0 + digit_match(n / 10, m / 10) if n % 10 != m % 10
return 1 + digit_match(n / 10, m / 10) if n % 10 == m % 10

Choose a reason for hiding this comment

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

This will fail for n = 20 and m = 20.

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.

Missed one

# Space complexity: ?
# Time complexity: O(n) if I had gotten it to work
# Space complexity: O(n)
def reverse_inplace(s)

Choose a reason for hiding this comment

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

  1. This method is not in place because s[1..-2] creates a new array.
  2. It's not working.

consider instead:

def reverse_in_place(s, left = 0, right = s.length -1)
  if left < right
    temp = s[left]
    s[left] = s[right]
    s[right] = temp
    return reverse_in_place(s, left + 1, right - 1)
  end
  return s
end

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