Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

water - marj #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

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

Nice work Marj, the majority of these work. The only major issue is the time/space complexities. Take a look at my comments and let me know what questions you have.

Comment on lines +3 to 5
# Time complexity: n
# Space complexity: 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 +12 to +14
# Time complexity: n^2
# Space complexity: n^2
def reverse(s) #was the answer to this supposed to be different from the one below??

Choose a reason for hiding this comment

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

👍

Comment on lines +22 to 24
# Time complexity: n
# Space complexity: 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.

👍 This is the same as the previous method and it's not in place.

Consider passing the front and rear indexes and swapping elements at each index.

def reverse_inplace(s, front = 0, last = s.length - 1)
  return s if front >= last

  temp = s[last]
  s[last] = s[front]
  s[front] = temp

  return reverse_inplace(s, front + 1, last - 1)
end

Comment on lines +55 to 57
# Time complexity: n
# Space complexity: n
def bunny(n)

Choose a reason for hiding this comment

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

👍 This works.

Comment on lines +64 to 66
# Time complexity: n^2
# Space complexity: n^2
def nested(s)

Choose a reason for hiding this comment

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

👍

Comment on lines 77 to 79
# Time complexity: ?
# Space complexity: ?
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 with O(n^2) space/time complexity.

Comment on lines +88 to 90
# Time complexity: n
# Space complexity: 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.

👍 But time/space complexity is O(n^2)

Comment on lines +99 to 104
# Time complexity: n
# Space complexity: n
#
# how many calls
# how expensive is each call
def digit_match(n, m)

Choose a reason for hiding this comment

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

👍 This is O(log n) if n is the size of the smaller of the two numbers (basically you divide by 10 each recursive call).

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