solve reverse-words-in-a-string problem