4073. Lexicographically Smallest String After Reverse
My accepted Python solution to LeetCode problem 4073, Lexicographically Smallest String After Reverse, running in 99ms.
- Difficulty: Medium
- Python
- Runtime 99ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 99ms, memory 17.4MB, accepted 2026-01-01.
class Solution:
def lexSmallest(self, s: str) -> str:
n = len(s)
result = s
for k in range(1, n + 1):
first_rev = s[:k][::-1] + s[k:]
last_rev = s[:n-k] + s[n-k:][::-1]
result = min(result, first_rev, last_rev)
return result