Reverse words in a given string
Easy Accuracy: 50.0% Submissions: 64282 Points: 2

Given a String S, reverse the string without reversing its individual words. Words are separated by dots.

Example 1:

S =
Explanation: After reversing the whole
string(not individual words), the input
string becomes

Example 2:

S = pqr.mno
Output: mno.pqr
Explanation: After reversing the whole
string , the input string becomes

Your Task:
You dont need to read input or print anything. Complete the function reverseWords() which takes string S as input parameter and returns a string containing the words in reversed order. Each word in the returning string should also be separated by '.' 

Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)

1 <= |S| <= 2000


We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Reverse words in a given string

Output Window