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 maintain two pointers, one at the start and one at the end, to reverse o...read more

Help your peers!
Select
Add answer anonymously...

Wipro Software Developer interview questions & answers

A Software Developer was asked 3d agoQ. What are the OOPS principles in C#?
A Software Developer was asked 3d agoQ. What is an extension method and how do you implement it?
A Software Developer was asked 3d agoQ. What is asynchronous programming?

Popular interview questions of Software Developer

A Software Developer was asked 2mo agoQ1. What languages have you used?
A Software Developer was asked 3mo agoQ2. What are your qualities?
A Software Developer was asked 5mo agoQ3. What is an operating system?

Top HR questions asked in Wipro Software Developer

A Software Developer was asked 1mo agoQ1. Tell me about yourself.
A Software Developer was asked 1mo agoQ2. Tell me about your work experience.
A Software Developer was asked 4mo agoQ3. What is your expected salary?
Wipro Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits