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

Katricia - Edges - Palindrome Check #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

krsmith7
Copy link

@krsmith7 krsmith7 commented Nov 11, 2018

time complexity: O(n) where n is the length of the string because we visit each character once
space complexity: O(3) which is shortened to O(1) because three new variables are instantiated

@shrutivanw
Copy link

Nice work on the algorithm.

Your space complexity will however end up being O(n) because you are deleting the white spaces and creating a new string object. To confirm, print my_phrase.object_id before and after line 7. You'll find that they are two different objects.

Can you think of an approach to avoid modifying the input string while keeping the space complexity constant? Hint: you will need to examine and ignore white spaces before line 14.

Give it some thought and then look the alternative solution here: https://github.com/Ada-C10/palindrome_check/blob/solution/lib/palindrome_check.rb

Slack me if you have any questions, or would like to discuss further.

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