Simple solution in 0(n)


#1

int i=0,j=s.length()-1;
while(i<=j){
swap(s[i],s[j]);
i++;j–;
}
stringstream ss(s);
string output,word;
while(ss>>word){
reverse(word.begin(),word.end());
output+=word;
output+=" ";
}
output.pop_back();
return output;