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 th...read more
Help your peers!
Add answer anonymously...
PayPal SDE-2 interview questions & answers
A SDE-2 was asked 11mo agoQ. Given a sorted array of integers, find the leftmost and rightmost index of a tar...read more
A SDE-2 was asked Q. Minimum Character Deletion Problem Statement You have been provided a string STR...read more
A SDE-2 was asked Q. Palindrome Checker Problem Statement Given an alphabetical string S, determine w...read more
Popular interview questions of SDE-2
A SDE-2 was asked 10mo agoQ1. Given a sorted array of integers, find the leftmost and rightmost index of a tar...read more
A SDE-2 was asked Q2. Minimum Character Deletion Problem Statement You have been provided a string STR...read more
A SDE-2 was asked Q3. Palindrome Checker Problem Statement Given an alphabetical string S, determine w...read more
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

