Last Updated: 24 Sep, 2025

Mirrored Reversal of String

Moderate
Asked in company
Euler Motors

Problem statement

You are given a string s that contains words separated by one or more spaces. Your task is to perform a "mirrored reversal" on the string.


A mirrored reversal consists of two steps:

1) Reverse the order of the words in the string.


2) Reverse the characters within each of those words.


Crucially, the original pattern of whitespace (the number of spaces between words, and any leading/trailing spaces) must be preserved and redistributed between the newly ordered words.


Input Format:
A single line containing the string s.


Output Format:
Print the modified string on a single line.