Skip to main content
LeetCode 917, Easy. Topics: Two Pointers, String. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:

Problem

Given a string s, reverse the string according to the following rules:
  • All the characters that are not English letters remain in the same position.
  • All the English letters (lowercase or uppercase) should be reversed.
Return s after reversing it.

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026