Leetcode Problem 2697. Lexicographically Smallest Palindrome

2697. Lexicographically Smallest Palindrome

Leetcode Solutions

Two Pointer Approach to Create the Lexicographically Smallest Palindrome

  • Initialize two pointers, left at the start of the string and right at the end of the string.
  • While left is less than right:
    • If the characters at left and right are not the same, replace the character at the higher index with the character at the lower index.
    • Increment left and decrement right.
  • Once the pointers meet or cross, the string is a palindrome and the process is complete.
UML Thumbnail

Brute Force Approach with Lexicographical Optimization

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...