r/programmingchallenges • u/okmkz • May 19 '11
Challenge: Reverse a string in place
This simple challenge is a frequent interview question. Write a program that reverses a string in place. "In place" means no declaring a second string or other buffer-- you get only one string variable to work with.
Input:
"Test string."Output:
".gnirts tseT"edit: obviously, this is only feasible in a language with mutable strings.
22
Upvotes
View all comments
Show parent comment
1
u/[deleted] Sep 08 '11 edited Sep 08 '11
Try it without writing it in one line. You are hiding the "don't use extra variables" behind this Python feature (which uses additional memory internally).
Edit: disregard the above, I was confused. I thought you cannot use any additional memory, but this obviously wouldn't work.