Reverse Words in a given string-Asked in Goldman Sachs Interviews
Problem Statement:
Given a String S, reverse the string without reversing its individual words. Words are separated by dots.
Input Format
The input consists of a single line containing a string ‘S’.
Output Format:
The output format contains a string which is the reversed version of the given string ‘S’.
Given:
i.like.this.program.very.much
Output:
much.very.program.this.like.i
Explanation of given Test Cases :
After reversing the whole string(not individual words), the input
string becomes much.very.program.this.like.i
Approach:
- Initially, reverse the individual words of the given string one by one, for the above example, after reversing individual words the string should be “i.ekil.siht.margorp.yrev.hcum”.
- Reverse the whole string from start to end to get the desired output “much.very.program.this.like.i” in the above example.