diff --git a/README.md b/README.md index 76f4476..c14e48e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # String Reverse -In this assignment, you'll design and implement one of the string manipulation functions that is commonly asked during interviews. -Remember that a string is an array of characters. Algorithms that worked on restricted arrays will work on strings as well. +In this assignment, you'll design and implement one of the string manipulation functions. +Remember that a string is an array of characters. Algorithms that worked on array data structure will work on strings as well. ## Exercise -* Design and implement a method to reverse a string *in place*. For example, if the method is called with input parameter of "Lovelace", the method should update the input string object to have the value "ecalevoL". -* Share and explain the time and space complexities for your solution. -* At minimum, your implementation should pass the basic tests. - -**Note**: Do not use Ruby provided functionality for `.reverse` and `.reverse!`. You may use `.length`. +* Design and implement a method to reverse a string *in place*. The method takes the string to be reversed as input parameter. +* Above the method, elaborate the comment to share the time and space complexity of your method. + * Your solution should optimize the space complexity as much as possible. In other words, do not use any more space than needed. + * If you explain the complexity in terms of *n*, be sure to explain what *n* stands for. +* For example, if the method is called with input parameter of "*Lovelace*", the method should update the input string object to have the value "*ecalevoL*". +* Notes: + * Do not use Ruby provided functionality for `.reverse` and `.reverse!`. + * You may use `.length` method available in the String class. + * You may access a character at a given index or set the value at a given index. diff --git a/lib/string_reverse.rb b/lib/string_reverse.rb index ad7dc0d..3b06ca5 100644 --- a/lib/string_reverse.rb +++ b/lib/string_reverse.rb @@ -1,4 +1,6 @@ # A method to reverse a string in place. +# Time complexity: ? +# Space complexity: ? def string_reverse(my_string) - my_string << "not implemented" + raise NotImplementedError end