Reverse words in a string

4.2

4 votes
Problem

Once upon a time, there was a young girl named Lily. She was very fond of playing word games and loved to challenge her friends with tricky questions.

One day, Lily's friends challenged her to come up with a story problem using the phrase "reverse words in a given string." Lily accepted the challenge and started thinking about how to turn this phrase into a story.

After a few minutes of brainstorming, Lily came up with an idea. She imagined a group of travelers who had lost their way in a dense forest. They had a map that showed the route to their destination, but the words on the map were all jumbled up and mixed together.

The travelers realized that they needed to unscramble the words on the map to find their way out of the forest. So, they decided to work together and came up with a plan. They would reverse the order of the words on the map, which would reveal the correct route to their destination.

With the help of their plan, the travelers were able to unscramble the words on the map and find their way out of the forest. They finally reached their destination, and they all celebrated their successful journey together.

From that day on, Lily's friends were impressed with her storytelling skills and continued to challenge her with more creative word games.

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

Example 1:

Input:

S = i.like.this.program.very.much

Output:

much.very.program.this.like.i

Explanation:

After reversing the wholestring(not individual words), the inputstring becomesmuch.very.program.this.like.i

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

After reversing the whole string (not individual words), the input string becomes much.very.program.this.like.i

Editor Image

?