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
1d
Reverse the letters of a string while keeping non-alphabet characters in their original position.
Iterate through the string and maintain two pointers, one at the start and one at the end, to reverse o...read more
Help your peers!
Add answer anonymously...
Top Wipro Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app