Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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*".
* <b>Notes</b>:
* 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.
4 changes: 3 additions & 1 deletion lib/string_reverse.rb
Original file line number Diff line number Diff line change
@@ -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