Reverse Word Order

String Manipulation Array Reverse Spaces

Problem: Reverse Word Order

Given a sentence as a string, write a function that returns a new string with the order of words reversed.

Details:

  • A word is defined as a sequence of non-space characters.
  • The input may contain leading or trailing spaces, as well as multiple spaces between words.
  • The output should contain words separated by a single space with no leading or trailing spaces.

Example:

Input: " Hello world! Today is a good day. "

Output: "day. good a is Today world! Hello"

Note: June 14 is celebrated as Flag Day in the United States, a time to reflect on unity and freedom. Use your coding skills to bring order out of chaos!