Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Reverse Only Letters

XPChallenge Points: 10
levelLevel: Easy

You are given a string s that may contain letters, digits, and special characters.
Your task is to reverse only the alphabetic characters (A–Z, a–z) while keeping all non-letter characters (digits, punctuation, symbols) in their original positions.
The order of the letters should be reversed as if all other characters did not exist.
Return the final string after applying this transformation.

Example 1:

Input: s = "xy-z@"

Output: "zy-x@"

Example 2:

Input: s = "a-bC-dEf-ghIj"

Output: "j-Ih-gfE-dCba"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result