DAYS
HOUR
MINS
SEC
Error
Given a string, your task is to reverse the string keeping the spaces intact to their positions.
Example 1:
Input:
S = "Help others"
Output: sreh topleH
Explanation: The space is intact at index 4
while all other characters are reversed.
Example 2:
Input:
S = "geeksforgeeks"
Output: skeegrofskeeg
Explanation: No space present, hence the
entire string is reversed.
Your Task:
You don't need to read input or print anything. Your task is to complete the function reverseWithSpacesIntact() which takes the string S as input and returns the resultant string by reversing the string while keeping all the spaces intact.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1<=|S|<=105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes