Open
Conversation
CheezItMan
reviewed
Oct 10, 2019
CheezItMan
left a comment
There was a problem hiding this comment.
Outstanding work! You hit all the learning goals here. Very well done!
Take a look at my comments and let me know if you have questions.
Comment on lines
+50
to
+65
| def word_reverse(my_sentence, word_start, word_end) | ||
| word_length = word_end - word_start + 1 | ||
|
|
||
| counter = 0 | ||
|
|
||
| while counter != word_length/2 | ||
| temp = my_sentence[word_start] | ||
| my_sentence[word_start] = my_sentence[word_end] | ||
| my_sentence[word_end] = temp | ||
|
|
||
| word_start += 1 | ||
| word_end -= 1 | ||
| counter += 1 | ||
| end | ||
| end | ||
|
|
Comment on lines
+39
to
+44
| until i == my_sentence.length/2 | ||
| temp = my_sentence[i] | ||
| my_sentence[i] = my_sentence[my_sentence.length - i - 1] | ||
| my_sentence[my_sentence.length - i - 1] = temp | ||
| i += 1 | ||
| end |
There was a problem hiding this comment.
You could also use the word_reverse method again to reverse the whole string.
| # Space complexity: ? | ||
| # Time complexity: O(n^2) because as the algorithm scales, each nested loop will run n number of times according to the input. | ||
| # Space complexity: O(1) because the same amount of memory will be used regardless of the input size. | ||
| def sort_by_length(my_sentence) |
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n^2) because as the algorithm scales, each nested loop will run n number of times according to the input. | ||
| # Space complexity: O(1) because the same amount of memory will be used regardless of the input size. |
There was a problem hiding this comment.
Technically since you are doing .split, you have O(n) space complexity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorting & Reverse Sentence