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

Dionisia Edges reverse_words #30

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

Conversation

larachan15
Copy link

Time complexity is O(n). I have an index loop that goes through the whole string and within that loop, each word has the letters swapped.
Space complexity is O(1) because I only have 4 variables regardless of the size of the input: my_words_start, my_words_end, index and temp.

my_words_start = index
my_words_end = index
end
end

Choose a reason for hiding this comment

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

Thought for further improvement: With the last test case scenario " evol ", your algorithm does work because for the first 4 spaces, on line 17 my_words_start will end up being greater than my_words_end. Can you intentionally add consideration for preceding and trailing consecutive white spaces?

my_words_end = index
end
end
return my_words

Choose a reason for hiding this comment

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

Since you're manipulating my_words in place, you don't need to return my_words. Line 28 could simply be return.

@shrutivanw
Copy link

Nice work! 👍

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