Amazon Interview Question
Software Engineer / Developersa string is always ended by '/0' we can use this end of string character to reverse string.
@pedro
Why dont you make a new string and than iterate the original string and start inserting characters in the beginning of new string.
It would be better.
And finding sub string also requires the length of string.
And its also O(n)
I guess we need to do it in place.
This is the one when we don't know the lenght.
- Pedro November 08, 2010public String recursiveReverseString(String s) {
if (s.length() <= 1)
return s;
else
return recursiveReverseString(s.substring(1)) + s.charAt(0);
}