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

Sigrid Benezra - Edges - Palindrome check #16

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

Conversation

sdbenezra
Copy link

Time complexity is O(n) because characters from each end of the string are compared in turn and that means you will make about n/2 comparisons depending on how many blank spaces there are. Dropping constants, you end up with O(n), linear time.

Space complexity is O(1) because there is only space needed to store a few variables for comparison, and that doesn't change no matter how long the string is.

@sdbenezra sdbenezra changed the title completed palindrome check Sigrid Benezra - Edges - Palindrome check Oct 7, 2018
end_index = my_phrase.length - 1
while beg_index < end_index

while my_phrase[beg_index] == " "

Choose a reason for hiding this comment

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

In the two nested inner loops, continue to check and confirm that beg_index is less than end_index before comparing the character at the index beg_index (or end_index) with a white space.

@shrutivanw
Copy link

Nice work! I added a minor comment to make your algorithm even more robust.

Slack me if you have any questions if you'd 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