392. Lexicographically Smallest Palindromic Permutation Greater Than Target
HardGreedy
You are given two strings s and target, each of length n, consisting of lowercase English letters. Return the lexicographically smallest string that is both a palindromic permutation of s and strictly greater than target. If no such permutation exists, return an empty string. A string a is lexicographically strictly greater than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b.
Examples
Input: baba abba
Output: baab
Explanation: The palindromic permutations of "baba" are "abba" and "baab". The smallest one strictly greater than "abba" is "baab".
Constraints
- 1 <= n == s.length == target.length <= 300
- s and target consist of only lowercase English letters.
Loading...
Run checks all cases above. Submit evaluates all test cases.