In this assignment, you'll design and implement one of the well-known string manipulation methods. Remember that a string is an array of characters. Algorithms that worked on restricted arrays will work on strings as well.
- Design and implement a method to reverse the words in a sentence in place. The string of words to be reversed in passed in as the input parameter to the method.
- Your algorithm should strive to optimize the space complexity as much as possible.
- For example, if the method is called with input parameter of "Yoda is awesome", then the method should update the input string object to have the value "awesome is Yoda".
- Note that the count of white spaces between words is preserved.
- Share and explain the time and space complexities for your solution in the comments above the method.
- If the complexity is shared in terms of n, your explanation must explain what n stands for.
Notes:
* Do not use Ruby provided functionality for .reverse
and .reverse!
.
* You may use .length
method available in the String class.