Two Pointers
3734. Lexicographically Smallest Palindromic Permutation Greater Than Target
A palindromic permutation is pinned down entirely by its left half: fix the first n/2 characters and the mirror writes the rest, with the single odd-count letter (when n is odd) forced into the center. So I never enumerate palindromes at all — I build the left half and let reflection do the work. If more than one letter has an odd count there is no palindrome to begin with, and I return the empty string right away.
Loading…