Skip to content

Practice Reverse Only Letters

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#917
LeetCode Problem

Reverse Only Letters

Problem Statement

Reverse the order of all uppercase and lowercase English letters in s while leaving every nonletter character at its original index. Return the resulting string.

Source: Reverse Only Letters on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "ab-cd"
Output
"dc-ba"

# Example 2

Input
s = "a-bC-dEf-ghIj"
Output
"j-Ih-gfE-dCba"

# Example 3

Input
s = "Test1ng-Leet=code-Q!"
Output
"Qedo1ct-eeLg=ntse-T!"

Constraints

1 <= s.length <= 100
s consists of characters with ASCII values in the range [33, 122].
s does not contain '\"' or '\\'.

Related LeetCode Problems

Practice more problems similar to Reverse Only Letters.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.