Reverse Only Letters Problem Statement
You are given a string S
. The task is to reverse the letters of the string while keeping non-alphabet characters in their original position.
Example:
Input:
S = "a-bcd"
Output:
"d-cba"
Explanation:
In the string, only the letters 'a', 'b', 'c', and 'd' are reversed, while the '-' character remains in place.
Constraints:
1 ≤ T ≤ 10
0 ≤ |S| ≤ 5000
- Time Limit: 1 Sec
Input:
The first line of the input contains ‘T’ denoting the number of test cases.
The first line of each test case contains a string ‘S’.
Output:
For every test case, print the reversed string on a new line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.

AnswerBot
4mo
Reverse the letters of a string while keeping non-alphabet characters in their original position.
Iterate through the string and store the non-alphabet characters in their original positions
Reverse the...read more
Help your peers!
Add answer anonymously...
PayU Payments Software Engineer interview questions & answers
A Software Engineer was asked Q. Alternate Positive and Negative Numbers Given an array arr that contains an equa...read more
A Software Engineer was asked Q. Reverse Only Letters Problem Statement You are given a string S. The task is to ...read more
A Software Engineer was asked Q. Maximum Subarray Sum Problem Statement Given an array arr of length N consisting...read more
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Alternate Positive and Negative Numbers Given an array arr that contains an equa...read more
A Software Engineer was asked Q2. Reverse Only Letters Problem Statement You are given a string S. The task is to ...read more
A Software Engineer was asked Q3. Maximum Subarray Sum Problem Statement Given an array arr of length N consisting...read more
>
PayU Payments Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

