2816. Lexicographically Smallest Palindrome
My accepted Python solution to LeetCode problem 2816, Lexicographically Smallest Palindrome, running in 75ms.
- Difficulty: Easy
- Python
- Runtime 75ms
- Memory 17.5MB
- 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 75ms, memory 17.5MB, accepted 2026-01-01.
class Solution:
def makeSmallestPalindrome(self, s: str) -> str:
chars = list(s)
left, right = 0, len(s) - 1
while left < right:
if chars[left] != chars[right]:
# Choose the smaller character for both
smaller = min(chars[left], chars[right])
chars[left] = smaller
chars[right] = smaller
left += 1
right -= 1
return ''.join(chars)