-
Notifications
You must be signed in to change notification settings - Fork 48
C. Gutierrez #34
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
base: master
Are you sure you want to change the base?
C. Gutierrez #34
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work you hit all the learning goals. Your reverse_sentence method could use a bit of a refactor as many of your methods are very repetitive. Other than that, excellent work.
| # A method to reverse the words in a sentence, in place. | ||
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(2n) The array is reviewed twice, once for spaces to populate the space array, and once more piecewise to do all the swaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So really O(n)
| until i == half_swap_limit | ||
| my_sentence[i], my_sentence[last_index - i] = my_sentence[last_index - i], my_sentence[i] | ||
|
|
||
| i += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that you reverse things a few times, this could be dryed up with a helper method.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(2n) The array is reviewed twice, once for spaces to populate the space array, and once more piecewise to do all the swaps | ||
| # Space complexity: O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are building a space array, so this would actually be: O(m) where m is the number of words.
| return my_sentence | ||
|
|
||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods seem pretty repetitive. Could they be condensed into one method?
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n2) | ||
| # Space complexity: O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically since you're doing .split, this should be O(n)
|
|
||
| if array_of_sentence[i].length > array_of_sentence[i + 1].length | ||
| array_of_sentence[i], array_of_sentence[i + 1] = array_of_sentence[i + 1], array_of_sentence[i] | ||
| i += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move the i += 1 to after the if statement and drop the else.
Sorting & Reverse Sentence