added solution to reverse the string word by word