Conversation
…igure out how toget it to pass all the tests.
CheezItMan
left a comment
There was a problem hiding this comment.
Not bad, your reverse_sentence isn't done in place, but it mostly works. The sort works, but it isn't a bubble, insertion or selection sort. Take a look at my comments and let me know your questions.
| end | ||
|
|
||
| if i == mid | ||
| my_sentence = words.join(", ") |
There was a problem hiding this comment.
Take a look at my how functions work lesson. Doing this doesn't affect the argument, which is why the tests fail.
| # Time complexity: ? | ||
| # Space complexity: ? | ||
| # Time complexity: O(n) because the amount of time it will take will increase as the length of the input increases. | ||
| # Space complexity: O(n) because the space increases as the inout increases. |
There was a problem hiding this comment.
You were asked to try to do this in place which mean O(1) space complexity. Can you see a way?
| while index < word_array.length | ||
| if word.length < sorted[index].length | ||
| sorted.insert(index, word) | ||
| break | ||
| elsif word.length == sorted[index].length | ||
| sorted.insert(index+1,word) | ||
| break | ||
| elsif index == sorted.length-1 | ||
| sorted.insert(index+1,word) | ||
| break | ||
| end | ||
| index += 1 |
There was a problem hiding this comment.
This is a very strange nonstandard sort. It works, but does a lot of extra inserts. Take a look at the textbook curriculum lesson on sorting and compare this to the standard sorts.
Sorting & Reverse Sentence